Event Organiser
[resolved] Add events to main loop and feed (13 posts)

  1. leemon
    Posted 4 years ago #


    Is there a way to show events in the main post loop and feed?

    Thanks in advance


  2. Stephen Harris
    Posted 4 years ago #

    I'm not sure about feeds, but for the main loop, just before the loop:

    global $wp_query;
    $args = array_merge( $wp_query->query, array( 'post_type' => array('post','event') ));
    query_posts( $args );

    The post type array should contain the name of all the post types you wish to appear.

    Note however, that as far as WordPress is considered this is just a post - so it will be displayed in the order that the event was published, not when the event occurs.

    Also, you will need to alter you theme to check (inside the loop) when the post is of post type 'event', so that you can format it differently (e.g. use the plug-in provided function to display dates, venue etc). Otherwise, it will be formated like the rest of your posts.

  3. leemon
    Posted 4 years ago #


  4. Scott DeToffol
    Posted 4 years ago #

    Anyone know how to apply this to a Genesis framework site (Focus child theme)? I'm looking at the home.php where the Genesis Grid Loop is called, but need some help.

  5. Stephen Harris
    Posted 4 years ago #

    I can't believe I ever suggested to use query_posts()....

    This is the preferred method:

    function eo2010_alter_main_page($query){
          if( $query->is_main_query() && is_front_page() ){
              $query->set('post_type', array('event'));
  6. jcnapw
    Posted 4 years ago #

    Hi, could you please tell a php newbie where exactly this code should go, if I want to add events to the post loop?

  7. Stephen Harris
    Posted 4 years ago #

    Functions.php :)

  8. jcnapw
    Posted 4 years ago #

    Wow, that was fast!!

    Thanks, that was my first thought. It displays events but also kicked out my theme sidebar and reads a fatal error. I'm trying to come up with a solution to show a few events, possibly separate from the recent posts on the index. What's the possibility of the plugin having the option make events sticky??

  9. sgreve
    Posted 4 years ago #

    Similar question: Can I have multiple loops on the page and then set one loop to display only events from one event-category using WP Query?

    Something like:

    <?php $tourdate = new WP_Query('taxonomy=event&post_type=event&category_name=my-date&showposts=1'); while ($tourdate->have_posts()) : $tourdate->the_post(); ?>

    or is that not possible?

  10. Stephen Harris
    Posted 4 years ago #

    @jcnapw - see sgreve's post :)

    @sgreve - you can have as as many loops as you like :). Your example should work, with the exception of the taxonomy query. Try this instead (there maybe syntax errors..):

        tax_query' => array(
    			'taxonomy' => 'event-category',
    			'field' => 'slug',
    			'terms' => 'my-term'
         'post_type' => 'event',
    $tourdate = new WP_Query($events_query);
    while ($tourdate->have_posts()) : $tourdate->the_post(); ?>
  11. jcnapw
    Posted 3 years ago #

    I'm trying to use the archive-event.php loop in a custom page template, but it's just not picking up the posts for me. (My theme is laid out quite differently from Twenty Ten, so when I activate template pages the loop works but the page is scrambled.) I must be missing something - so what else is necessary other than what is between <?php /* Start the Loop */ ?> and <!----The Loop ends--> in archive-event.php?

  12. leemon
    Posted 3 years ago #

    Thanks, Stephen Harris

  13. Stephen Harris
    Posted 3 years ago #

    @leemon - no worries!

    @jcnapw - in your case I'd recommend enabling templates, moving the plug-in provided templates to your theme and editing them there so it fits with your theme. See this page: http://www.harriswebsolutions.co.uk/event-organiser/documentation/editing-the-templates/

    If you do want to create a custom page template, then you'll need to something similar to my previous post:

    $events_query = array(...);//Set event query
    $myevents = new WP_Query($events_query);
    if( $myevents->have_posts() ):
      while ($myevents->have_posts()) : $myevents->the_post();
       //Display content here

    As the 'main loop' refers to the query for the page itself, not the events.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Event Organiser
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic