admin管理员组

文章数量:1389750

Has anyone encountered a DB error when using pre_get_posts to display ALL posts on a CPT archive page?

This error...

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1' at line 1]

SELECT SQL_CALC_FOUND_ROWS dfr34_wp_posts.ID FROM dfr34_wp_posts WHERE 1=1 AND dfr34_wp_posts.post_type = 'our-work' AND (dfr34_wp_posts.post_status = 'publish' OR dfr34_wp_posts.post_status = 'acf-disabled' OR dfr34_wp_posts.post_status = 'private') ORDER BY dfr34_wp_posts.post_date DESC LIMIT 0, -1

I'm using the following code and the error only shows if i try and show all posts, if i just put a number in it works.

 function work_query_order($query){
        if( ! is_admin() && is_post_type_archive( 'our-work') && $query->is_main_query()  ):
                    $query->set( 'posts_per_page', -1);         
        endif;    
};
add_action( 'pre_get_posts', 'work_query_order', 5 );

本文标签: databasepregetposts causings DB error when using ( 39postsperpage391)