WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. leemon
    Member
    Posted 2 years ago #

    Hi!

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

    Thanks in advance

    http://wordpress.org/extend/plugins/event-organiser/

  2. Stephen Harris
    Member
    Plugin Author

    Posted 2 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
    Member
    Posted 2 years ago #

    Thanks!

  4. Scott DeToffol
    Member
    Posted 2 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
    Member
    Plugin Author

    Posted 2 years ago #

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

    This is the preferred method:

    add_action('pre_get_posts','eo2010_alter_main_page',5,1);
    function eo2010_alter_main_page($query){
    
          if( $query->is_main_query() && is_front_page() ){
              $query->set('post_type', array('event'));
          }
    }
  6. jcnapw
    Member
    Posted 2 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
    Member
    Plugin Author

    Posted 2 years ago #

    Functions.php :)

  8. jcnapw
    Member
    Posted 2 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
    Member
    Posted 2 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
    Member
    Plugin Author

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

    $events_query=array(
        tax_query' => array(
    		array(
    			'taxonomy' => 'event-category',
    			'field' => 'slug',
    			'terms' => 'my-term'
    		)
    	),
         'post_type' => 'event',
         'posts_per_page'=>1.
    )
    
    $tourdate = new WP_Query($events_query);
    while ($tourdate->have_posts()) : $tourdate->the_post(); ?>
  11. jcnapw
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

    Thanks, Stephen Harris

  13. Stephen Harris
    Member
    Plugin Author

    Posted 1 year 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
      endwhile;
    endif;
    wp_reset_postdata();

    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

About this Topic