The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Ambrosite Next/Previous Post Link Plus
pre_get_posts query order not the same (2 posts)

  1. elclanrs
    Posted 3 years ago #

    I have a custom post-type called "scholars" and I'm sorting the archive with the pre_get_posts hook, like so:

    add_action('pre_get_posts', 'my_queries');
    function my_queries($query)
      if (!$query->is_main_query()) return;
      if ($query->is_post_type_archive('scholars')) {
        $query->set('posts_per_page', -1);
        $query->set('meta_key', 'year');
        $query->set('orderby', 'meta_value_num');

    It works just fine in the archive page, posts are ordered by year but then I use the plugin in the single page and the order is not the same, I can't even tell what the order is TBH, is not by date, is not by custom meta apparently. What could be the problem?

    <nav class="scholars-navigation">
      <span class="prev"><?php previous_post_link_plus('meta_key=year&order_by=numeric') ?></span>
      <h2><?php the_title() ?></h2>
      <span class="next"><?php next_post_link_plus('meta_key=year&order_by=numeric') ?></span>


  2. ambrosite
    Plugin Author

    Posted 3 years ago #

    I'm not sure, that code looks like it should work. If you want, you can temporarily uncomment line 200 of the plugin code:

    // echo $query . '<br />';

    That will cause the SQL query that is generated by the plugin to be printed on the screen. If you paste it here, I'll check to see whether it looks correct.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Ambrosite Next/Previous Post Link Plus
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic