Support » Plugin: WordPress Infinite Scroll - Ajax Load More » Custom Function Repeating First Page Results

  • Resolved timothylarson

    (@timothylarson)


    I am working on an upcoming events list for this site: https://catchfireuniversity.com

    Since I need the events to only show if they are upcoming and need to sort the events by the event date (a custom meta field, not the date of the post) I am using my own custom args in my functions.php file.

    I noticed in your documentation you state not to modify the “paged” or “offset” query parameters, so I haven’t set either of these.

    However, the first page of results is repeating when I click the “Load More” button rather than getting the second page.

    What am I doing wrong?

    This is my shortcode:
    [ajax_load_more id="upcomingevents" scroll="false" button_label="Load More"]

    And this is my function:

    function upcoming_events($args, $id){
    	$args = array(
    		'post_type'		=> 'event',
    		'meta_key'		=> 'event-date',
    		'meta_value'		=> date("U"),
    		'meta_compare'		=> '>',
    		'orderby'		=> 'event-date',
    		'order'			=> 'ASC',
    		'posts_per_page'	=> 3,
    	);
    	return $args;
    }
    add_filter( 'alm_query_args_upcomingevents', 'upcoming_events');

    Any help would be greatly appreciated.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    Hi @timothylarson,
    Interesting… I bet the issue is you are creating an entirely new $args variable rather than modifying the existing as seen in the docs.
    https://connekthq.com/plugins/ajax-load-more/docs/filter-hooks/#alm_query_args

    Try this:

    <?php
       function upcoming_events($args, $id){
          
    	$args['post_type'] = 'event';
    	$args['meta_key'] = 'event-date';
    	$args['meta_value'] = date("U");
    	$args['meta_compare'] = '>';
    	$args['orderby'] = 'event-date';
    	$args['order'] = 'ASC';
    	$args['posts_per_page'] = 3;
    	
    	return $args;
    }
    add_filter( 'alm_query_args_upcomingevents', 'upcoming_events');
    Thread Starter timothylarson

    (@timothylarson)

    That fixed it, thanks!

    The only thing I had to modify was I had to move the “posts_per_page” into the shortcode rather than the function. When it was in the function, it was skipping a couple results for some reason.

    It all works perfectly now, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Function Repeating First Page Results’ is closed to new replies.