WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] Infinite scroll? (17 posts)

  1. Chantal Coolsma
    Member
    Posted 1 year ago #

    Is it possible with Event Manager to use infinite scroll like pinterest?

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

  2. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    if you mean like on their website, it's not possible out the box so would require custom coding.

    However you could probably get that to work combining jQuery AJAX and a bit of php code to serve the next events. maybe one of these scroll jquery plugins would help http://www.webdeveloperjuice.com/2012/05/26/10-aggressively-used-jquery-infinite-scroll-plugins-for-endless-paging/

  3. Chantal Coolsma
    Member
    Posted 1 year ago #

    It's for a new site, so probably it is better to skip Events Manager and code it by hand with custom post types.

  4. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    if you're going to code it by hand, you'd probably be doing the same amount of work (unless of course you're using an infinite scroll plugin for WP...). the trickiest bit is adding the infinite scroll, grabbing the event/cpt info in PHP would probably be along the same lines.

  5. Chantal Coolsma
    Member
    Posted 1 year ago #

    This new site just has events with an startdate/time and enddate/time. Should be shown on homepage on published date (with infinite scroll) or the visitor can click on a category and see the events in that category sorted by startdate with infinite scroll.

  6. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    If very simple, CPTs could work for you, you'd just need to add datepickers. EM essentially would do the same thing (since they are cpts too) but with more meta info (e.g. location etc.), so it depends on your project I guess.

    I think in this case since you want publish date, WP_Query would be best used, which you can do with EM by searching for the event post type and doing a custom field query for _start_ts, which is a timestamp for the start date/time - http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters

    You'd probably do the same thing for a normal CPT.

    I long for some time to write a good tutorial on this :)

  7. Chantal Coolsma
    Member
    Posted 1 year ago #

    Thanks Marcus. Will think about this. Looks promising. So the admin/editor uses EM to enter events, but on the front-end you will use your own queries.

  8. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    yes, plus if you wanted to then you have the single event pages, shortcodes, widgets etc. available in EM you still have at your disposal

  9. Chantal Coolsma
    Member
    Posted 1 year ago #

    Marcus,

    Can you help me please to get the right WP_Query? This doesn't return any event:

    $now = getdate();
    
    $args = array(
    	'post_type' => 'event',
    	'meta_query' => array(
    		array(
    			'key' => 'event_end_date',
    			'value' => $now,
    			'compare' => '>',
    			'type' => 'date'
    		)
    	)
    );
    
    // The Query
    $the_query = new WP_Query( $args );

    Without the meta_query array it gives me all events. What am I doing wrong?

  10. Chantal Coolsma
    Member
    Posted 1 year ago #

    Also doesn't work... Outputs timestamp for "now" but nothing more:

    $now = date(time());
    
    $args = array(
    	'post_type' => 'event',
    	'meta_query' => array(
    		array(
    			'key' => '_end_ts',
    			'value' => $now,
    			'compare' => '>',
    			'type' => 'date'
    		)
    	)
    );
    
    echo $now;
    
    // The Query
    $the_query = new WP_Query( $args );
  11. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    that looks about right, you now need to loop through your query to output the information.

    as explained in http://codex.wordpress.org/Class_Reference/WP_Query#Usage

  12. Chantal Coolsma
    Member
    Posted 1 year ago #

    I have...

    <?php
    
    $now = date(time());
    
    $args = array(
    	'post_type' => 'event',
    	'posts_per_page' => 20,
    	'meta_query' => array(
    		array(
    			'key' => '_end_ts',
    			'value' => $now,
    			'compare' => '>',
    			'type' => 'date'
    		)
    	)
    );
    
    echo $now;
    
    // The Query
    $the_query = new WP_Query( $args );
    
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    	echo '<li>';
    	the_title();
    	echo '</li>';
    endwhile;
    
    // Reset Post Data
    wp_reset_postdata();
    
    ?>

    When I remove the meta_query array (so only filter on post_type 'event') it returns all events. With the meta_query it doesn't return anything.

    $now returns the timestamp of this moment.

  13. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    I get asked this a lot, so I've written a snippet which'll hopefully avoid repetition:

    function my_em_wp_query(){
    	$args = array(
    		'post_type' => 'event',
    		'posts_per_page' => 100,
    		//'meta_query' => array( 'key' => '_start_ts', 'value' => current_time('timestamp'), 'compare' => '>=', 'type'=>'numeric' ),
    		'orderby' => 'meta_value_num',
    		'order' => 'ASC',
    		'meta_key' => '_start_ts',
    		'meta_value' => current_time('timestamp'),
    		'meta_value_num' => current_time('timestamp'),
    		'meta_compare' => '>='
    	);
    
    	// The Query
    	$query = new WP_Query( $args );
    
    	// The Loop
    	while($query->have_posts()):
    	$query->next_post();
    	$id = $query->post->ID;
    	echo '<li>';
    	echo get_the_title($id);
    	echo ' - '. get_post_meta($id, '_event_start_date', true);
    	echo '</li>';
    	endwhile;
    
    	// Reset Post Data
    	wp_reset_postdata();
    }
    add_shortcode('em_wp_query','my_em_wp_query');

    what's interesting is that whilst adding meta_query should work, for some reason it doesn't and then all events are shown. Will look into that one day when time permits.

  14. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    btw, the above is in the form of a shortcode, e.g. [em_wp_query], adjust as needed.

  15. Chantal Coolsma
    Member
    Posted 1 year ago #

    Thanks. This seems to work.

    Now I have to find a way to kick off the query again to give the next x results. Maybe make it a function which accepts an offset. If no offset is given, just start from the beginning.

  16. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    for that you'll need to do research :)

    e.g. google 'WP_Query pagination' first result - http://wordpress.org/support/topic/adding-pagination-to-a-wp_query-loop?replies=16

  17. Chantal Coolsma
    Member
    Posted 1 year ago #

    Yay! Got it to work :-)

    $now = date(time());
    
    $args = array(
    	'post_type' => 'event',
    	'posts_per_page' => 2,
    	'paged' => get_query_var('page'),
    	'orderby' => 'meta_value_num',
    	'order' => 'ASC',
    	'meta_key' => '_start_ts',
    	'meta_value' => current_time('timestamp'),
    	'meta_value_num' => current_time('timestamp'),
    	'meta_compare' => '>='
    );
    
    // The Query
    $the_query = new WP_Query( $args );

    Custom WP_Query in a page template which is set as homepage.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags