On the hotel list page of the category, I would like to check if category A belongs to the category hotel and display it.

Asked 1 years ago, Updated 1 years ago, 70 views

Hello
I use wordpress to create a hotel website.

***What you want to do***
In the hotel search page, we use the drop-downs to create pages that can be filtered by destination and travel themes.
"I would like to check if the category ""Travel Theme"" is registered in the post of the category ""Hotel"" and display only the registered travel theme or destination."

For example, the following categories:
Category Hotel (id=18)
Category Destination (id=15)=>Child Category "Japan=>Tokyo", "UK=>London", "France=>Paris"
Category Travel Theme (id=2)=>Child Category "Shopping", "Eating Walk", "Romantic"

Article A is a hotel, a tour theme, and the destination is Japan=>Tokyo
Article B is a hotel, romantic travel theme, destination is France=>Paris

In this case, I would like to display only eating and walking and romantic in the drop-down options of the travel theme, and only Japan and France in the destination options, but I don't know how to get each category on category.php.There are many other child categories for destinations and travel themes.

***Current status**
The code below shows all categories, and it is not filtered.

<!--category-18.php-->
<!--Destination Category Retrieval-->
$destinations=get_categories(array(
   'parent' = > 15,
   'hide_empty' = > 1,
   'hierarchical' = > 0
));
foreach($destinations as$dest): ?>
<option class="category__filter__dropdown" value="<?phpecho$dest->term_id;?>"data-destination="<?phpecho$dest->term_id;?>">
       <?phpecho$dest->name;>
</option>
<?php endforeach;?>

<!--Travel theme category acquisition-->
$travel_topics=get_categories(array(
       'parent' = > 2,
       'hide_empty' = > 1,
       'hierarchical' = > 0
));
foreach($travel_topics as$cat): ?>
<option class="category__filter__dropdown" value="<?phpecho$cat->term_id;?>"data-reisethema="<?phpecho$cat->term_id;?>">
       <?phpecho$cat->name;>
</option>
<?php endforeach;?>

It would be very helpful if you could give me some advice.Thank you.
I asked the same question to teratail, but I didn't get any comments yet, so I posted the question here as well.

php wordpress

2022-09-30 18:13

1 Answers

I didn't understand the content of the question, but I'm sorry for the inconvenience, but I'll try to post it.
Searching is very difficult because it involves many things.
Wouldn't it be a good idea to use get_categories to exclude only the categories you need in 'include' or the ones you don't need in exclude?
https://wpdocs.osdn.jp/%E9%96%A2%E6%95%B0%E3%83%AA%E3%83%95%E3%82%A1%E3%83%AC%E3%83%B3%E3%82%B9/get_categories

There seem to be countless categories created, so I wonder if get_categories will take all the category information and pull out unnecessary things like "I don't need this because it's a category included in this."

Anyway, it would be nice if I could make an array of IDs for the categories I need.
Then, if you specify 'include', you can take it out freely.
Why don't you try it with ingenuity?


2022-09-30 18:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.