Support Forums

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

Viewing 7 posts - 1 through 7 (of 7 total)
  • Mike Reed
    #205262

    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?

    Trevor Moderator
    #205272

    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.

    Mike Reed
    #205274

    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

    Trevor Moderator
    #205278

    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

    Mike Reed
    #205283

    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().'"]' );
    		} 
            
    	}
    	?>
    Trevor Moderator
    #205285
    This reply has been marked as private.
    Mike Reed
    #205287
    This reply has been marked as private.
Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Order (group) results by taxonomy term by default’ is closed to new replies.