Home › Forums › General Issues › Alter pagination of an existing query to go by a custom field › Reply To: Alter pagination of an existing query to go by a custom field
Ok figured out the problem. In case anyone is dealing with similar issues:
if ( isset( $query->query_vars['post_type'] ) && ( 'post' === $query->query_vars['post_type'] || is_single() ) ) {
$query->set( 'orderby', 'meta_value' );
$query->set( 'meta_key', 'event_start' );
$query->set( 'order', 'ASC' );
$query->set( 'paged', get_query_var( 'paged' ) );
$query->set( 'posts_per_page', get_option( 'posts_per_page' ) );
$query->set( 'meta_query', array(
'relation' => 'AND',
array(
'key' => 'event_start',
'compare' => '>=',
'value' => date( 'Y-m-d H:i:s', strtotime( '-8 hours' ) ),
'type' => 'DATETIME',
),
) );
}
return $query;
Only paged and pages_per_page had to be added. Now it is working proplery.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.