WordPress.org

Support

Support » Plugins and Hacks » Events Manager » [Resolved] Infinite scroll?

[Resolved] Infinite scroll?

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author Marcus

    @netweblogic

    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/

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

    Plugin Author Marcus

    @netweblogic

    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.

    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.

    Plugin Author Marcus

    @netweblogic

    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 🙂

    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.

    Plugin Author Marcus

    @netweblogic

    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

    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?

    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 );
    Plugin Author Marcus

    @netweblogic

    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

    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.

    Plugin Author Marcus

    @netweblogic

    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.

    Plugin Author Marcus

    @netweblogic

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

    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.

    Plugin Author Marcus

    @netweblogic

    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

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘[Resolved] Infinite scroll?’ is closed to new replies.
Skip to toolbar