DocumentationOnline documentation for Ajax Load More
Ordering by Meta Query
Ajax Load More supports a single orderby parameter, however, the WP_Query class allows for extending this by ordering by a specific Meta Query.
The code below uses the alm_query_args filter to append an ever-present Meta Query to the query arguments and then order the results by the clause.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php function my_movie_listing( $args, $id ){ // [ajax_load_more id="movie_listing"] // Custom meta query clause. $meta_date_args = [ 'key' => 'my_date_field', 'value' => date( "Ymd" ), 'compare' => '>=' , 'type' => 'DATETIME' ]; // Add to meta_query. $args['meta_query']['date_clause'] = $meta_date_args; // Add custom ordering. $args['orderby'] = [ 'date_clause' => 'ASC', ]; return $args; } add_filter( 'alm_query_args_movie_listing', 'my_movie_listing', 10, 2 ); |