Support

Account

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');