I am using something like these arguments to order the archive loop, to order posts by a custom field.

$args = array(  
    'category_name' => $filter_cat, 
    'posts_per_page' => -1,
    'meta_key' => 'year_start',
    'orderby' => array( 'meta_value_num' => 'DESC', 'title' => 'ASC' )  

On single.php, how can I add a link to the next post and previous post in the same order as the main query above?

I want to have the possibility to skip from one post to another through all posts (not in one category).

1 Answer 1


So from the research I have done into this I've found out the follow:

To display the Text as a Link, without the Post Title but within the same category you would use the follow

<?php next_post_link( '%link', 'Next post in category', TRUE ); ?>

To do it with the same custom taxonomy the following applies

<?php next_post_link( '%link', 'Next post in taxonomy', TRUE, '', 'my_custom_taxonomy' ); ?>

I'm sure by looking into next_post_link and previous_post_link you will be able to find a way to link the links with your custom field.

Best of luck :)

  • thank you but how can I change the order to a custom field?
    – buckdanny
    Jan 27, 2016 at 11:42
  • I don't quite understand what you mean? This will allows them to skip through from one post to another and not by category
    – Stephen
    Jan 27, 2016 at 11:43
  • sorry, I need to skip through one post to another in a certain order, the order is based on a custom field.
    – buckdanny
    Jan 27, 2016 at 17:42
  • I've updated my answer to hopefully benefit you :)
    – Stephen
    Jan 27, 2016 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.