• Resolved silvrey

    (@silvrey)


    Hello,

    i have installed the Plugin “Simple Custom Post Order” with the newest version and it works fine.
    But the only problem is that the order of the “Related Posts” is in the wrong order.
    It only shows the oldest ones but it should show the newest ones.

    I tried to change this behavior with some code in the child theme but it always changed the post order on the main page too.

    I tried to fix this issue with the “pre_get_posts” action. But i found no solution and also found no similar question in the forum here.

    Thanks!

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @silvrey,

    To stop it from changing on the main page as well please check if it’s not main_query,
    example: $query->is_main_query()
    https://developer.wordpress.org/reference/hooks/pre_get_posts

    If it is, you shouldn’t alter the query.

    Warmly,
    Mihaela

    Thread Starter silvrey

    (@silvrey)

    Hello,

    thanks for your quick answer!

    I already tried this, but it always returns true so my code does not get executed for the related posts part.

    I tried the following code and it shows the results as i want to:

    
    function custom_pre_get_posts($wp_query) {
    	$wp_query->set('orderby', 'menu_order');
    	$wp_query->set('order', 'ASC');
    }
    
    add_action('pre_get_posts', 'custom_pre_get_posts');

    I don’t know exactly if this could destroy something but until now it works fine.

    I also don’t understand why someone would like to show the oldest posts as related posts.

    Thanks!

    No worries! Happy to hear that worked.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Change order of related posts’ is closed to new replies.