Tell us what you are trying to do?
If you go on this website (hidden link) you can see right under the search engine a list of main taxonomy (level 0). When we click on one category, it shows the listings in that specific category. I made this with elementor. But this is what I want :
If I click on a category, I would like to see ,on the second page, a list of the child category of this main category instead of the main category.
For example, in Animal Care there is two child categories : Pet supplies AND Veterinary clinics. So when I click on Animal Care, the page that will load will show the listings in Animal Care directory and replace the taxonomy list for the child-taxonomy list of those two child categories. And if I click on a child categories, that will show a list of child categories of this child category, etc.
Is there any documentation that you are following?
I looked on Toolset forum but get a bit confused with different options. I want to make sure I do it the right way.
Is there a similar example that we can see?
If you go on this classified website on the "job" category : hidden link
You can see right under the search engine a list of sub-categories (child categories). If, for example, you click on Education, the page that load show everything in that category but also show a new sub-categories list for that specific categorie (Education). I want to reproduce the same thing in my website.
What is the link to your site?
hidden link
Hello,
I assume we are talking about section "Search by category" in the URL you mentioned above.
As you mentioned above:
I made this with elementor
Do you want to make it with Elementor or Toolset?
If you are going to make it with Toolset, it is possible with a taxonomy view + some PHP codes, for example:
1) Create a taxonomy view(ID: 123),
- Query terms of your taxonomy "listing-category"
- In views loop, display below link:
<a href="?wpv-listing-category=[wpv-taxonomy-slug]">[wpv-taxonomy-title]</a>
2) Add below PHP codes into your theme files:
add_filter('wpv_filter_taxonomy_query', function($query, $settings, $views_id){
if($views_id == 123 && isset($_GET['wpv-listing-category'])){
$term = get_term_by('slug', $_GET['wpv-listing-category'], 'listing-category'); // here replace "listing-category" with your custom taxonomy slug
if($term){
$query['child_of'] = $term->term_id;
}
}
return $query;
}, 99, 3);
Please replace 123 with your taxonomy view's ID.
More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query
Hi,
Thank you for your help. I have done what you told me to do but I'm getting a full list of all categories, child included. What I want is the main categories list without the child and when I click on one categorie, this list change to show the child of the category that I just clicked on. Do you want access to my dashboard and see what I'm doing wrong.
The view used for the search page is : Main Search listings
The view created for the taxonomy list is : Listing category list
Where I put the PHP code : WordPress Dashboard - Setting - PHP inserter (scroll to the bottom)
You can see attached the list I'm getting when I add the taxonomy view to the Main Search view.
Thank you for your help,
Above codes works fine in my localhost, since it is a custom PHP codes problem, please provide a test site with the same problem, fill below private message box with your website credentials and FTP access, I need to test and debug it in a live website
I have tried the credentials you provided above, it is not valid, I get these errors:
lifeflow.jfbweb****.com is currently unable to handle this request.
HTTP ERROR 500
Please check it, thanks
Sorry about that. It should work now. Let me know. Thank you!
I have tried the credentials you provided above lots of time, same errors:
There has been a critical error on your website. Please check your site admin email inbox for instructions.
You can follow our document to provide a full copy of your website in below private message box:
https://toolset.com/faq/provide-supporters-copy-site/
Also point out the problem page URL and view URL, where I can edit your custom PHP codes, I need to test and debug it in my localhost, thanks
Thanks for the details, for the problem:
What I want is the main categories list without the child and when I click on one categorie, this list change to show the child of the category that I just clicked on
Please try this, edit the taxonomy view "Listing category list", ID 412:
hidden link
in section "Query Filter", add a filter:
Select taxonomy terms whose parent is None.
Then test again
Hi Luo,
It is working great! Last thing that I would like to show just over this sub-category list is the actual taxonomy where this view is shown. If you go for example on this page : hidden link
This page show all result for Mental Health and show a list of child taxonomy. I would like just over this list to show the actual title of the taxonomy showed, in this case, Mental Health. What is the shortcode I can use to show that information?
I have tried [wpv-taxonomy-title] but that show nothing.
Thank you for your help!
Please try to modify the PHP codes, from:
$query['child_of'] = $term->term_id;
To:
unset($query['child_of']);
$query['parent'] = $term->term_id;
More help:
https://developer.wordpress.org/reference/classes/wp_term_query/__construct/
'parent'
(int|string) Parent term ID to retrieve direct-child terms of.
Hi,
I'm not sure that you understood my question. The taxonomy list is working perfect! I just want to show, over this taxonomy list, the actual taxonomy showed in the actual search. Look my print screen.
The example on my printscreen is for the actual search page : hidden link
So we see in the URL that the trigger is calling the listing in Mental Health taxonomy. Can I just show the taxonomy "Mental Health" over the child taxonomy list? So visitor know which taxonomy is listed on the page at the moment?
Thank you!
Jeff
Thanks for the details, since you are passing term's slug as URL parameter, so it needs custom codes, for exmaple, add below codes into your theme file "functions.php":
add_shortcode('get_term_by_url_param', function($atts){
$res= '';
$atts = shortcode_atts( array(
'url_param' => 'wpv-listing-category',
'tax' => 'listing-category',
), $atts);
if(isset($_GET[$atts['url_param']]) && $_GET[$atts['url_param']] != ''){
$term = get_term_by('slug',$_GET[$atts['url_param']], $atts['tax']);
if($term){
$res = $term->name;
}
}
return $res;
});
Then use above shortcode to display the actual search term's name:
My issue is resolved now. Thank you!