• Resolved Rafael Fischmann

    (@rfischmann)


    Hi!

    I’m back using Relevanssi after a while and tried to make this work once again, but it doesn’t seem to be working this time: https://wordpress.org/support/topic/reverse-order-by-date-2/

    I want the latest posts to show up first after the most relevant ones. I of course am using “DESC” for post_date, but as I said it doesn’t seem to be making any difference in results.

    Any help, please? Thanks!

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

    (@msaari)

    Something like this?

    add_filter( 'relevanssi_modify_wp_query', function( $query ) {
    $query->set( 'orderby', array( 'relevance' => 'desc', 'post_date' => 'desc' ) );
    return $query;
    } );

    This won’t have any noticeable effect compared to just sorting by relevance. This will sort the posts by relevance, and if there’s a tie in relevance (which is rare), those tied posts are then sorted by date.

    What exactly do you mean with “I want the latest posts to show up first after the most relevant ones.”? Can you give me a more concrete example of how this would work, like a list of posts with dates and made-up relevance scores, and how they should be sorted?

    Thread Starter Rafael Fischmann

    (@rfischmann)

    That’s exactly what I want, @msaari, but somehow — maybe for the same reason as the code for RSS feeds in the other topic — it’s not working for me.

    What I mean is like this example here: https://d.pr/i/7GY73C

    It first sorts by relevance (great), but the latest posts — probably with the same lower relevance — are shown from the oldest to the newest. I want to invert that.

    Plugin Author Mikko Saari

    (@msaari)

    Are you looking at this in the WP admin search the screenshot is from? Relevanssi does not reliably work in the admin search; for hierarchical post types, the search just does not use Relevanssi.

    Are the results the same in the Relevanssi admin search (Dashboard > Admin search)?

    Thread Starter Rafael Fischmann

    (@rfischmann)

    Yes, that’s a search from the WP admin.

    The results are the same from Relevanssi admin search, but the order is a bit different.

    Plugin Author Mikko Saari

    (@msaari)

    Is the order in the Relevanssi admin search correct? Is the date sorting right there? If you change the sorting completely in the function (e.g. set orderby to post_date), does that change take effect?

    Thread Starter Rafael Fischmann

    (@rfischmann)

    Really sorry for the trouble here too, @msaari. I finally caught the problem: it was a setting I previously changed in my server’s OPcache that forced a really strong cache over PHP files. Fixed that and now it’s working great!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Reverse order by date’ is closed to new replies.