[wp-trac] [WordPress Trac] #34474: sql error with wp_query and posts_per_page param

WordPress Trac noreply at wordpress.org
Wed Oct 28 15:13:54 UTC 2015


#34474: sql error with wp_query and posts_per_page param
--------------------------+-----------------------------
 Reporter:  nicmare       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  4.3.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 i have a simple query array:
 {{{
 query_posts( $args );
 }}}

 print_r of $args:

 {{{
 Array
 (
     [post_type] => product
     [funktion] => gerauschpegelanzeige
     [error] =>
     [m] =>
     [p] => 0
     [post_parent] =>
     [subpost] =>
     [subpost_id] =>
     [attachment] =>
     [attachment_id] => 0
     [name] =>
     [static] =>
     [pagename] =>
     [page_id] => 0
     [second] =>
     [minute] =>
     [hour] =>
     [day] => 0
     [monthnum] => 0
     [year] => 0
     [w] => 0
     [category_name] =>
     [tag] =>
     [cat] =>
     [tag_id] =>
     [author] =>
     [author_name] =>
     [feed] =>
     [tb] =>
     [paged] => 0
     [comments_popup] =>
     [meta_key] =>
     [meta_value] =>
     [preview] =>
     [s] =>
     [sentence] =>
     [fields] =>
     [menu_order] =>
     [category__in] => Array
         (
         )

     [category__not_in] => Array
         (
         )

     [category__and] => Array
         (
         )

     [post__in] => Array
         (
         )

     [post__not_in] => Array
         (
         )

     [tag__in] => Array
         (
         )

     [tag__not_in] => Array
         (
         )

     [tag__and] => Array
         (
         )

     [tag_slug__in] => Array
         (
         )

     [tag_slug__and] => Array
         (
         )

     [post_parent__in] => Array
         (
         )

     [post_parent__not_in] => Array
         (
         )

     [author__in] => Array
         (
         )

     [author__not_in] => Array
         (
         )

     [ignore_sticky_posts] =>
     [suppress_filters] =>
     [cache_results] => 1
     [update_post_term_cache] => 1
     [update_post_meta_cache] => 1
     [posts_per_page] => -1
     [nopaging] =>
     [comments_per_page] => 50
     [no_found_rows] =>
     [order] => DESC
     [meta_query] => Array
         (
             [0] => Array
                 (
                     [key] => gerauschpegelanzeige
                     [value] => 1
                 )

         )

 )
 }}}

 for some reason i get this error:
 WordPress-Datenbank-Fehler: [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 3]
 SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN
 wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( (
 wp_postmeta.meta_key = 'gerauschpegelanzeige' AND
 CAST(wp_postmeta.meta_value AS CHAR) = '1' ) ) AND wp_posts.post_type =
 'product' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status =
 'acf-disabled' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID
 ORDER BY wp_posts.post_date DESC LIMIT 0, -1

 when i change "posts_per_page" to a high number (i.e. 100), then it works.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/34474>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list