Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Combining Post Type and Taxonomy Grouping
- This topic has 9 replies, 2 voices, and was last updated 1 year, 5 months ago by
Ernest Marcinko.
-
AuthorPosts
-
December 6, 2024 at 9:16 am #52169
melsaunders
ParticipantHello,
I would like to group search results in a way that combines Post Type Grouping and Taxonomy Grouping, as follows:
The first group should have the heading “Looking For” and display some Taxonomies.
Below that, there should be separate groups for each Post Type (e.g., one group for posts, another for products, another for pages, etc.).
(See Image)Could you please guide me on how to set this up ?
Thank you!
December 6, 2024 at 10:27 am #52172Ernest Marcinko
KeymasterHi,
Well, that exact layout may not be possible as combining groupings is not possible.
However there is still hope, by utilizing the “Other results” group.
For that I would set it up like this: https://i.imgur.com/LllFNKT.pngDecember 6, 2024 at 10:37 am #52173melsaunders
ParticipantHello,
Thank you for your response! I understand that combining groupings isn’t natively possible. However, I was wondering if this could be achieved with custom code, such as by editing the result templates or using filters/hooks?
December 6, 2024 at 3:41 pm #52178Ernest Marcinko
KeymasterCustom coding would be very complicated here I think.
Have you tried the solution I suggested: https://i.imgur.com/LllFNKT.png
That should be almost exactly what you want.December 9, 2024 at 8:25 am #52189melsaunders
ParticipantYes, I tried the solution you suggested, and it works well! Thank you for that.
I’d like to refine it further:
Is it possible to add a link to the archive page for each post type at the end of its group?
Can I reduce the number of results displayed for each group?December 10, 2024 at 8:58 am #52208Ernest Marcinko
KeymasterHi,
Is it possible to add a link to the archive page for each post type at the end of its group?
I’m afraid that’s not possible. I recall someone may have asked this very same question, it might be on the future features list, I am not sure. It is possible it may get added later on as a core feature.Can I reduce the number of results displayed for each group?
Yes – under the Search Sources -> Limits panel, you can set the number of results for both taxonomy terms and post types: https://i.imgur.com/uHoyuvq.png
If you want somewhat matching number of results for each post type, you can try this option as well, however it may cause some funky number of results in this case, so make sure to test it.December 10, 2024 at 10:27 am #52212melsaunders
ParticipantThank you for the solution provided regarding limiting the number of results; I’ll give it a try!
As for adding a link to the archive page for each post type at the end of its group, I experimented with the following code in the group-footer.php file, and it seems to be working fine:
<span> <?php $post_type = get_post_type($r->id); if ($post_type === 'products') { // If the post type is 'products', add a link to the products archive page echo '<a href="' . home_url('/products') . '">See All Products</a>'; } elseif ($post_type === 'post') { // If the post type is 'post', add a link to the articles archive page echo '<a href="' . home_url('/resources') . '">See All Articles</a>'; } else { // Otherwise, just display the post type echo esc_html($post_type); } ?> </span>It seems to do the trick for now. Let me know if there’s anything I should be cautious about with this approach!
December 10, 2024 at 11:46 am #52221Ernest Marcinko
KeymasterThat is actually perfect in my opninion. I was going to suggest the results templating as well, so this is definitely a very good solution.
December 10, 2024 at 11:47 am #52223melsaunders
ParticipantThanks so much for the feedback! Glad the solution works. I really appreciate your help!
If anything else comes up, I’ll be sure to reach out. Thanks again!
December 10, 2024 at 11:48 am #52224Ernest Marcinko
KeymasterYou are very welcome!
-
AuthorPosts
- You must be logged in to reply to this topic.