Skip to main content
9 votes

Can the Next/Prev Post links be ordered by menu order or by a meta key?

Tried to hook in without success. Might be just a problem of my configuration, but for those who can't make the hook work, here is the simplest solution: <?php $all_posts = new WP_Query(array( ...
Zibellino's user avatar
  • 190
4 votes

Can the Next/Prev Post links be ordered by menu order or by a meta key?

FWIW here’s how you can order by menu_order for a specific custom post type: /** * Customize adjacent post order */ add_filter('get_next_post_sort', function($order) { if (is_singular('...
Ted Whitehead's user avatar
4 votes

Filter next_post_link() and previous_post_link() by meta_key?

i had a pretty similar problem, needed to sort and exclude several posts from prev/next navigation. problem with @cfx's solution was: its not capable for ajax: the is_singular() function returns false,...
honk31's user avatar
  • 1,408
3 votes
Accepted

Working with Next and Prev links in Single Taxonomy Templates

The next_post_link() and previous_post_link() functions take in_same_term parameter, which is set to FALSE by default. You will find a complete description of the functions here and here. ...
nmr's user avatar
  • 4,521
3 votes

Wordpress next/prev links Issue

From the Codex (emphasis mine): In standard usage (within the default, unaltered loop) next_post_link will generate a link to a post that is newer (more recent) than the current post. This is ...
Jacob Peattie's user avatar
3 votes

How can I get next post id after current post id for custom post type

If you are using the code inside a custom post type template, then the get_next_post() will get the next post for you. Then you can use the ->ID and get it's ID. So: $next_post = get_next_post(); $...
Johansson's user avatar
  • 15.4k
3 votes
Accepted

How to make my pagination loop continuously?

You could add an else to both ifs and get the first post/latest post: <?php $nextPost = get_next_post(); if($nextPost) { $nextPostID = $nextPost->ID; ?> <a class="...
dbeja's user avatar
  • 1,079
3 votes

Can the Next/Prev Post links be ordered by menu order or by a meta key?

Based on @Szabolcs Páll's answer I've created this utility class with helper methods to be able to get posts of type by menu order and get the next and previous post by menu order as well. I've ...
Eli Jayson's user avatar
2 votes

Can the Next/Prev Post links be ordered by menu order or by a meta key?

Based on @Szabolcs Páll's answer and bbloomer's post on adding next/prev buttons in WooCommerce Single Product Page, I created this code. It sorts all products by meta key and adding prev/next ...
Elron's user avatar
  • 159
2 votes
Accepted

Displaying the author of next and previous posts in pagination?

Yes, you can do that. Change <?php previous_post_link(); ?> and <?php next_post_link(); ?> with the following code: For previous post: <?php $prev_post = get_previous_post(); ...
MaximOrlovsky's user avatar
2 votes

Can I use get_adjacent_post for specific categories?

What you call "slugs" here is more appropriately called terms. It is a little confusing with native taxonomies because it turns into tautology: individual categories are terms of the category taxonomy....
Rarst's user avatar
  • 99.9k
2 votes

next_posts_link not working in custom loop

only just use echo and get_ <?php $args = array( 'post_type' => 'post', 'posts_per_page' => 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() )...
NikHiL Gadhiya's user avatar
1 vote

next_posts_link not working in custom loop

I know this post is a bit old but I got stuck in the same point and probably other will stumble upon in question to find an answer. I wanted to create a custom loop in the file index.php and I solved ...
Matt_Geo's user avatar
  • 111
1 vote
Accepted

copy wp-include/link-template to child theme

The article you linked to already has a solution written by the co-founder of WordPress Mike Little: https://digwp.com/2012/05/post-navigation-author-category/#comment-36899 In the spirit of ...
Tom J Nowell's user avatar
  • 60.6k
1 vote

Wordpress post pagination continuous

get_next_post returns null if there is no post anymore. And then get_permalink will have a null value for $next_post, so it will get the permalink for the current post, resulting in linking to the ...
Jos's user avatar
  • 426
1 vote
Accepted

Make `previous_post_link()` Function Show The Post After Next i.e. Jump A Post

$current_id = get_the_ID(); $cpt = get_post_type(); $all_ids = get_posts(array( 'fields' => 'ids', 'posts_per_page' => -1, 'post_type' => $cpt, 'order_by' => '...
Alan's user avatar
  • 161
1 vote

Get previous/next post from (specific) category

When in_same_term parameter in get_next_post() / get_previous_post() function is set to TRUE, a post is selected from any category assigned to the current post. As you wrote, you can not use the ...
nmr's user avatar
  • 4,521
1 vote

Can the Next/Prev Post links be ordered by menu order or by a meta key?

None of the answers listed here or on the internet in general that I could find as of this writing seemed to offer a reasonably simple/elegant solution for presenting the Next/Prev Post links ordered ...
Collie's user avatar
  • 111
1 vote

Wordpress post next/prev not working

I made some updates in your code. Please, try this updated version. <div id="demo"> <?php $wp_query = new WP_Query( array( 'category_name' => 'Case Study', '...
BlueSuiter's user avatar
  • 1,188
1 vote

Wordpress pagination link always leads to home page

Pagination is unlikely to work on anything which is not the main query and there is not much point to try to force it to work in other places. Use pre_get_posts filter if modifying the main query will ...
Mark Kaplun's user avatar
  • 23.7k
1 vote

Wordpress pagination link always leads to home page

<!-- section list events--> <?php if(get_query_var('paged')){ $paged = get_query_var('paged'); } elseif (get_query_var('page')) { $paged = get_query_var('page'); } else { $...
BlueSuiter's user avatar
  • 1,188
1 vote

Get next post in same category not working WP 4.7.4

Use the_post_navigation( $args ); to display next and previous links in your template for a single post. To restrict links to the same category, your $args array, in its simplest form, should be: $...
Frank P. Walentynowicz's user avatar
1 vote

Previous_post and Next_post - Custom Post Type

You want to change the in_same_term value to TRUE as follows: function crunchify_post_navigation(){ ?> <div class="arrowNav"> <div class="arrowLeft"> <?...
TomC's user avatar
  • 1,316
1 vote

Displaying the author of next and previous posts in pagination?

You can create a custom function. For this you need to use // Add in single.php where you want to show next icon. $nextPost = get_next_post(); // Get the next post detail $nextPostID = $nextPost-&...
Aftab's user avatar
  • 1,391
1 vote

altering %title

Unfortunately, your logic doesn't quite work out. The reason is because the order of operations, just like math, works inside to outside. So, your short_title() function is running with just passing ...
socki03's user avatar
  • 1,952
1 vote

Next and prev. post link ONLY within category

Copy the single.php page from your Parent theme and Paste it to your Child-theme's directory. Open the single.php from child-theme directory and add the following code at the end of file [before ...
Surender's user avatar
1 vote

Next and prev. post link ONLY within category

If you need to restrict prev or next post link for specific custom taxonomy or term, custom post type, custom field or format then you should try Ambrosite Next/Previous Post Link Plus. This plugin ...
Muhammad Usama's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible