Home › Forums › Add-ons › Gallery Field › Empty array when ordering posts by meta_value › Reply To: Empty array when ordering posts by meta_value
What happens if you add $query->is_main_query()
to your if statement?
function allstar_buzzworthy_published_sort( $query ) {
// If not the admin section
if ( !is_admin() && $query->is_main_query()) {
// If on a taxonomy page
if ( is_tax() ) {
$query->set( 'meta_key', 'date_published' );
$query->set( 'orderby', 'meta_value' );
$query->set( 'order', 'DESC' );
}
}
}
add_action( 'pre_get_posts', 'allstar_buzzworthy_published_sort' );
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.