Support » Themes and Templates » [Resolved] Previous & next post link in custom queries
4 years, 5 months ago
Using a custom query, I can’t get the next_post_link() to work.
Query is built like this:
$temp = $wp_query;
$wp_query = new WP_Query();
$paged = get_query_var('paged');
while ($wp_query->have_posts()) : $wp_query->the_post();
$do_not_duplicate = $post->ID;
<-- does things -->
» <?php previous_post_link(); ?>
» <?php next_post_link(); ?>
<?php $wp_query = null; $wp_query = $temp;?>
Any thought would be much appreciated!
Let me clarify your question. I do not get the clear point here. Do you want the post navigation working for custom post type (Nieuws) ?
next_post_link() is for single post nav;
try next_posts_link() http://codex.wordpress.org/Function_Reference/next_posts_link
Alchymyth: same deal, nothing happens.
I’m displaying a news item through a custom post type query.
I want a link to the previous item, relative to the current one showing.
Try to use this :
[Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]
Let me know if the code works.
Sorry, I moved the code in pastebin. Try this : http://pastebin.com/GBzGVfV5
Let me know if the code is working.
No, I only get the ‘not found’.
Seems weird though to have ‘if have posts’ before doing a query. My guess it, it won’t have posts yet. 🙂
Solved. Had to be in the loop (in contradiction to pagination).