admin管理员组

文章数量:1414874

I am having an issue on an archive page. Everything seems to be working fine, exept the fact that "the_query" returns only two posts, when it should return 10 of them.

I wanted to debug the query so I used the following line :

echo "<hr>Last SQL-Query: {$the_query->request}";

Which returns :

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 = 'client' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value DESC LIMIT 0, 2

When I run it in phpMyAdmin, it returns 2 IDs. When I remove the end (" LIMIT 0, 2"), it then returns the 10 IDs I was expecting.

Where does this limit come from ? I am quite suprised !

Here is my php code :

        $the_query = new  WP_Query
         (
                  array
                  (
                        'meta_key'=> 'client',
                        'orderby' => 'meta_value',
                        'order'   => 'DESC'
                  )
        );

echo "<hr>Last SQL-Query: {$the_query->request}";

I then have another bit that displays posts, but it works fine since the two posts are displayed properly.

Thank you for your help !

I am having an issue on an archive page. Everything seems to be working fine, exept the fact that "the_query" returns only two posts, when it should return 10 of them.

I wanted to debug the query so I used the following line :

echo "<hr>Last SQL-Query: {$the_query->request}";

Which returns :

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 = 'client' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value DESC LIMIT 0, 2

When I run it in phpMyAdmin, it returns 2 IDs. When I remove the end (" LIMIT 0, 2"), it then returns the 10 IDs I was expecting.

Where does this limit come from ? I am quite suprised !

Here is my php code :

        $the_query = new  WP_Query
         (
                  array
                  (
                        'meta_key'=> 'client',
                        'orderby' => 'meta_value',
                        'order'   => 'DESC'
                  )
        );

echo "<hr>Last SQL-Query: {$the_query->request}";

I then have another bit that displays posts, but it works fine since the two posts are displayed properly.

Thank you for your help !

Share Improve this question asked Oct 25, 2016 at 6:37 Grégoire LlorcaGrégoire Llorca 571 silver badge10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Use the posts_per_page parameter in your WP_Query to show a given number of posts.

When you don't provide this parameter, the query takes default value which can be set in backend on https://example/wp-admin/options-reading.php.

本文标签: wp queryWPQuerygtrequest has a limit