WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. elclanrs
    Member
    Posted 1 year 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>
    </nav>

    http://wordpress.org/plugins/ambrosite-nextprevious-post-link-plus/

  2. ambrosite
    Member
    Plugin Author

    Posted 1 year 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

About this Topic