• Resolved generalmacbeth

    (@generalmacbeth)


    So, the main thing that interested me about Event Manager was its use of custom post types. However, I’m trying to run a simple query and cannot order them by their event start date. Here’s my code:

    <?php
    			$args = array(
    				'post_type' => 'event',
    				'posts_per_page'=>-1,
    				'orderby' => 'event_start_date',
    				'order' => 'ASC'
    				)
    		?>
    		<?php $my_query = new WP_Query($args); ?>
    		<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
            		<article class="happening_ListItem clearfix">
    
            			<a title="View Event" class="happening_OpenLink" href="<?php the_permalink(); ?>">+</a>
    
    					<div class="happening_ListDate">
    						<div class="happening_ListDateInner">
    							<div class="happening_Month"><?php the_time('F'); ?></div>
    							<div class="happening_Day"><?php the_time('j'); ?></div>
    							<div class="happening_Year"><?php the_time('Y'); ?></div>
    						</div>
    					</div>
    
    					<div class="happening_ListDescription">
    						<div class="happening_ListName">
    							<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    						</div>
    						<div class="happening_ListMeta">
    							<p><?php echo wp_trim_words( get_the_content(), 20, '...' ) ?></p>
    						</div>
    					</div>
    				</article>
    			<?php endwhile; wp_reset_postdata();?>

    All I’m trying to do is list the posts in order. Additionally, is there a way to only show future events this way? Any help here would be greatly appreciated.

    http://wordpress.org/extend/plugins/events-manager/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter generalmacbeth

    (@generalmacbeth)

    Ah, I think I see now. Throw out WP_Query altogether and just iterate through the array output by EM_Events::get… Nice that there’s this feature (I thought you could only echo out that array preformatted).

    Here’s what I have now (just showing the id of the event right now for testing), but it seems to be working perfectly:

    <?php $EM_Events = EM_Events::get( array('scope'=>'future', 'orderby'=>'event_start_date') ); ?>
            <?php foreach ($EM_Events as $evt) : ?>
                    <?php print_r($evt); ?>
            		<article>
            			<?php echo $evt->event_id; ?>
                            </article>
           <?php endforeach; ?>

    Note: I’m only printing the $evt for reference so I know what keys in the object to retrieve.

    Thread Starter generalmacbeth

    (@generalmacbeth)

    This may be asking too much from the method I’m using to display events, but I’d like to add pagination to this method. Naturally this doesn’t work:

    <?php $EM_Events = EM_Events::get( array('scope'=>'future', 'orderby'=>'event_start_date', 'limit'=>2, 'offset'=>2, 'pagination'=>1) ); ?>
            <?php foreach ($EM_Events as $evt) : ?>
                    <?php print_r($evt); ?>
            		<article>
            			<?php echo $evt->event_id; ?>
                            </article>
           <?php endforeach; ?>

    But is there any way to make pagination work here?

    maybe you can try template file events-manager/templates/templates/events-list.php and see how we did it.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Doing a simple query and ordering by event date’ is closed to new replies.