WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Previous & next post link in custom queries (9 posts)

  1. OrT
    Member
    Posted 2 years ago #

    Hi all,

    Using a custom query, I can't get the next_post_link() to work.

    Query is built like this:

    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query();
    $paged = get_query_var('paged');
    $wp_query->query('showposts=1'.'&paged='.$paged.'&post_type=Nieuws');
    while ($wp_query->have_posts()) : $wp_query->the_post();
    $do_not_duplicate = $post->ID;
    
    <-- does things -->
    
    endwhile;  ?>
    <div class="contentnavigation">
    » <?php previous_post_link(); ?>
    » <?php next_post_link(); ?>
    </div>
    <?php $wp_query = null; $wp_query = $temp;?>

    Any thought would be much appreciated!

  2. Kharis Sulistiyono
    Member
    Posted 2 years ago #

    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) ?

  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

    next_post_link() is for single post nav;
    try next_posts_link() http://codex.wordpress.org/Function_Reference/next_posts_link

  4. OrT
    Member
    Posted 2 years ago #

    Alchymyth: same deal, nothing happens.

  5. OrT
    Member
    Posted 2 years ago #

    Some clarification:

    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.

  6. Kharis Sulistiyono
    Member
    Posted 2 years ago #

    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.

  7. Kharis Sulistiyono
    Member
    Posted 2 years ago #

    Sorry, I moved the code in pastebin. Try this : http://pastebin.com/GBzGVfV5

    Let me know if the code is working.

  8. OrT
    Member
    Posted 2 years ago #

    kharisblank:

    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. :-)

  9. OrT
    Member
    Posted 2 years ago #

    Solved. Had to be in the loop (in contradiction to pagination).

Topic Closed

This topic has been closed to new replies.

About this Topic