Home › Forums › General Issues › get_field not working with pre_get_posts › Reply To: get_field not working with pre_get_posts
The reason why is that you are setting all queries to only look in the post type ‘cpt_operator’. If you are trying to change the posts per page for this post type then you should not be setting the post type, you should be checking the query to see if WP is doing a query on that post type.
function edit_query($query) {
if ( !is_admin() && $query->is_main_query() &&
isset($query->query_vars['post_type']) &&
$query->query_vars['post_type'] == 'cpt_operator') {
$query->set( 'posts_per_page', 5);
return $query;
}
}
add_action( 'pre_get_posts', 'edit_query');
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.