0

IF specified fields parameter as 'ids' then my WP_query working ok (but i want all fileds).

    $query3 = new WP_Query(array('post_type' => array('post'),
    'posts_per_page' => -1,
    'fields'         => 'ids',
    'date_query' => array(
        array(
            'column' => 'post_modified_gmt',
            'after'  => '1 month ago'
            )
        )
));

  [request] => SELECT   x_posts.ID FROM x_posts  WHERE 1=1  AND ( 
   x_posts.post_modified_gmt > '2017-08-27 12:02:06'
 ) AND x_posts.post_type = 'post' AND (x_posts.post_status = 'publish')  
 ORDER BY x_posts.post_date DESC 
[post_count] => 14
[found_posts] => 14
[max_num_pages] => 0
[max_num_comment_pages] => 0

If i don't use fields parameter. I get.

    [post_count] => 215
    [found_posts] => 14

But SQL query is correct.

[request] => SELECT   x_posts.* FROM x_posts  WHERE 1=1  AND ( 
   x_posts.post_modified_gmt > '2017-08-27 12:02:06'
 ) AND x_posts.post_type = 'post' AND (x_posts.post_status = 'publish')  
 ORDER BY x_posts.post_date DESC 

How can I fix it?

  • A little confused by your syntax. Normally when you use WP_Query you specify post_status = 'publish' right in WP_Query. So unless I am misunderstanding perhaps that's the issue, you just need to specify that you only want published posts? – WebElaine Sep 27 '17 at 15:41
0

post_status='publish' is default yo WP_Query so you not need specified. As you can see real SQL query is ok. And all returned results are with status publish. looks like that only post_modified_gmt > 'xxx' is not respect.

Currenly use construction with

 'fields'         => 'ids',

so get only 14 post id's and next

 foreach($query3->posts as $id) {
                $post = get_post($id);
 // ...

but i don't know if it is optimal way

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.