• Resolved faglork

    (@faglork)


    Hi!

    How can I set the sort oder of the related posts to DATE?

    Great plugin btw, I gave it a 5.

    Cheers,
    Alex

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Ajay

    (@ajay)

    Thank you.

    To order by date, you can create a filter function for crp_posts_orderby

    Untested:

    function crp_sort_by_date( $orderby ) {
       return ' post_date';
    }
    add_filter( 'crp_posts_orderby', 'crp_sort_by_date' );
    
    Thread Starter faglork

    (@faglork)

    thx, but it doesn’t work …

    cheers,
    Alex

    Plugin Author Ajay

    (@ajay)

    What happens when you do it?

    Thread Starter faglork

    (@faglork)

    Sorry for the long delay …

    Nothing happens. Same unordered output as before.

    I forgot to disable the cache …

    When I add these lines, there appears to be no content reationship altogether, the output is totally unrelated.

    Cheers,
    Alex

    • This reply was modified 7 years, 10 months ago by faglork.
    Plugin Author Ajay

    (@ajay)

    That’s likely because of the sorting relevance being lost.

    Did anyone get this working? It seems to show the oldest posts within my 365 day setting but I want it to show the newest posts.

    Thread Starter faglork

    (@faglork)

    Well, no. But I limited the range to 100 days, and to same category. This gives fairly recent, relevant results.

    I use

    Fetch related posts only from: Same categories

    Disable contextual matching X

    Disable contextual matching ONLY on attachments and custom post types: X

    Related posts should be newer than: 100 days

    Find related posts based on content as well as title: X

    Limit content to be compared: 60

    This is ok for me. So far the best results. Would be nice if sorted by date, though.

    Cheers,
    Alex

    • This reply was modified 7 years, 5 months ago by faglork.

    I just figured it out after reading through the core files…. This is tested and is working. This works if you want to sort by post date (newest first)

    Copy this into your functions.php.

    
    function crp_sort_by_date( $orderby ) {
       return ' wp_posts.post_date DESC';
    }
    add_filter( 'crp_posts_orderby', 'crp_sort_by_date' );
    

    This can be marked as resolved

    Thread Starter faglork

    (@faglork)

    You just made my day!

    THANK YOU!

    Alex

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Sort related posts by date’ is closed to new replies.