Looking for support? You can access the support system via your account.
- This topic has 6 replies, 2 voices, and was last updated 5 years, 1 month ago by .
The topic ‘Order (group) results by taxonomy term by default’ is closed to new replies.
Looking for support? You can access the support system via your account.
Forums › Forums › Search & Filter Pro › Order (group) results by taxonomy term by default
Hi, I’m trying to get search results ordered by a CPT taxonomy term. I thought the Relevanssi (premium) might work for this, but it doesn’t appear to be influencing the result at all.
Something like:
function calder_tax_weight( $match ) {
if ( has_term( ‘for-sale’, ‘listing_status’, $match->doc ) ) {
$match->weight = $match->weight * 5;
}
return $match;
}
add_filter( ‘relevanssi_match’, ‘calder_tax_weight’ );
Is there another way to do this with S&F that doesn’t involve a separate loops in the results template?
Our plugin does not sort by taxonomy terms. The reason is that you can have multiple tag/category/taxonomy terms) on individual posts, and which term would we use to sort on? WordPress stores terms for tags/categories/taxonomies in arrays
A sort requires a single value field, so on some custom fields this can be done (but not on ones that can have multiple values). Be aware that if there is no value for a taxonomy/custom field the post will be omitted from the results entirely.
That makes sense. Can you provide a little more info on how Relevanssi is integrated into the S&F results? I’m going to troubleshoot a bit more, but will probably end up using a meta value.
-Is a search term required for Relevanssi filtered results?
-How do the respective indexes interact?
Thanks
What our form does is the text search first, and receives back an array of Post ID’s, sorted if requested. It then further filters this list per the other filters on the page. Only this text search would use Relevanssi, or the default WordPress search. Relevanssi has no effect on results where the form has no text search.
If you want to sort, you may be able to use this filter:
https://searchandfilter.com/documentation/action-filter-reference/#edit-query-arguments
Thanks for confirming. What I was seeing with that filter is that WP Query does not have a direct way to group or sort by tax term. Existing solution all use a loop in a template.
For this application, duplicating the loop worked fine:
<?php
while ($query->have_posts())
{
$query->the_post();
if ( get_post_type( get_the_ID() ) == 'business_listing' && has_term('for-sale', 'listing_status') ) {
echo do_shortcode( '[pods name="business_listing" template="Listing Snippet" id="'.get_the_ID().'"]' );
}
}
?>
<?php
while ($query->have_posts())
{
$query->the_post();
if ( get_post_type( get_the_ID() ) == 'business_listing' && has_term('under-loi', 'listing_status')) {
echo do_shortcode( '[pods name="business_listing" template="Listing Snippet" id="'.get_the_ID().'"]' );
}
}
?>
The topic ‘Order (group) results by taxonomy term by default’ is closed to new replies.
© 2024 Search & Filter Support. All Rights Reserved.
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
We also use cookies to store items in your cart as well as allowing your to login on the site.
You can adjust all of your cookie settings by navigating the tabs on the left hand side.
By continuing to use this site, you also agree to our Privacy Policy.
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
*Other cookies used for logging in and cart functions will only be used when you use those features and cannot be disabled.
If you disable these cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!
More information about our Cookie Policy