Home › Forums › Front-end Issues › Customize main query to sort by ACF number field › Reply To: Customize main query to sort by ACF number field
I also tried this approach, but this crashed the site with a fatal error:
function tas_pre_get_posts( $query ) {
// do not modify queries in the admin
if( is_admin() ) {
return $query;
}
// only modify queries for 'post' post type
if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'post' ) {
$query->set('orderby', 'meta_value');
$query->set('meta_key', 'tas_album_order');
$query->set('order', 'DESC');
}
// return
return $query;
}
add_action('pre_get_posts', 'tas_pre_get_posts');
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.