• Hi Mikko,

    im trying to filter results alphabetically by post title. I read the documentation and using the string

    add_filter( ‘relevanssi_orderby’, function( $orderby ) { return ‘post_title’; } );
    add_filter( ‘relevanssi_order’, function( $order ) { return ‘asc’; } );

    But nothing happen.

    Any suggestions ?

    Kind regards,

    Antonio

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Mikko Saari

    (@msaari)

    You are using Search & Filter Pro, so it’s possible Search & Filter is overriding this. See if Search & Filter Pro has a way to adjust the order of the results. Also, where have you added these lines?

    Thread Starter antonionev99

    (@antonionev99)

    So doing a check I had to activate the check order by relevance in search & filter to ensure that that function had an effect on the results. While there is the possibility of always having a double filter with that function? that is, in addition to the alphabetical order (as an image) being able to sort the result first by the searched word (Roma), always leaving the post titles in alphabetical order (with all the results with the searched word first) and then everything else

    Plugin Author Mikko Saari

    (@msaari)

    If you search for “Roma”, all the results will have the word “Roma” in them. So which ones will be first and which ones will be in alphabetical order?

    In theory, there’s no limit to how you can sort the search results. Relevanssi gives you full control. You just have to be able to define the algorithm, and if you’re looking for something more complicated, do it in PHP code.

    Thread Starter antonionev99

    (@antonionev99)

    If i search Roma i need first of all, the posts order alphabetically that is associated to the search word Roma, and then all the other post ever ordered alphabeticcaly.
    Roma , or another city, is a meta_value “citta”. So when i search Roma i need firsy
    :
    – all post order by post_title alphabetically with the meta_value rome , and then the other

    Now im using this:

    add_filter( ‘relevanssi_orderby’, function( $orderby ) { return ‘post_title’; } );
    add_filter( ‘relevanssi_order’, function( $order ) { return ‘asc’; } );

    Plugin Author Mikko Saari

    (@msaari)

    Ok, that makes it much clearer.

    This is, unfortunately, a case where you need code. This can’t be done with relevanssi_orderby parameters. You need to sort the posts by post title, and then have a function that takes the custom field matches and moves them first.

    This would be fairly easy to do with Relevanssi Premium. With the free version, it’s harder. Using the relevanssi_hits_filter is the key in any case.

    Thread Starter antonionev99

    (@antonionev99)

    Can i use relevanssi_hits_filter with free version ?

    • This reply was modified 1 day, 4 hours ago by antonionev99.
    Plugin Author Mikko Saari

    (@msaari)

    Yes, it’s available in both versions.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.