Support » Plugin: Ambrosite Next/Previous Post Link Plus » pre_get_posts query order not the same

  • 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>

Viewing 1 replies (of 1 total)
  • Plugin Author ambrosite


    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.

Viewing 1 replies (of 1 total)
  • The topic ‘pre_get_posts query order not the same’ is closed to new replies.