Support » Plugins » Getting navigation to work when using get_posts

  • I’m a real beginner at this so bear with me if this is really basic. I’ve looked around but can’t seem to find a good answer.

    I’m running a custom loop for the plugin Event Organiser, using its eo_get_events() which is analogous to WordPress’ built-in get_posts().

    I’ve managed to get the loop to run and display the events, but the navigation isn’t showing up (older/newer posts). I think that this has something to do with the wp_query and that I somehow have to “hijack” it, but I havent managed to find any code that works with get_posts, only with other versions of the loop.

    Anyone have any ideas? Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • That’s right, get_posts is the wrong thing to use for the default navigation – you want to WP_Query. This excepts exactly the same arguments as get_posts (and eo_get_events) but you will need to explicitly set post_type to ‘event’.

    If you want to know about adapting the main query see this Codex page or try WordPress Stack Exchange.

    Thanks again for your quick answer Stephen 🙂

    I’m trying this, but it only brings back regular posts no matter what I put after post_type. I’ve tried “event” and “draft”, but it always just gives the regular posts. Any ideas?

    $the_query = new WP_Query( 'post_type=event' );
    <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
    	<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    <?php wp_reset_postdata();?>

    You second line is a second query which over-rides the first, (and post type isn’t set). Also, if you want pagination, then you don’t want to show all posts on the first page, so posts_per_page should something other than -1.


    $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
         $the_query = new WP_Query( array(
            'posts_per_page'=> 10,
            'paged'=> $paged

    And omit the line

    Draft is a post status, not type by the way. If you have any more questions about this, please use WordPress Stack Exchange as this isn’t really to do with Event Organiser :D.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Getting navigation to work when using get_posts’ is closed to new replies.