admin管理员组文章数量:1130349
I am struggling with WordPress, and was looking at WP_Query. We usually pass an array of arguments to get result against.
$args = array(
'post_type' => 'post',
'post_per_page' => '2',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'ignore_sticky_posts' => true
);
$the_query = new WP_Query( $args );
Is there any way to print out $the_query in raw form for testing purpose just like we do in CodeIgniter with $this->db->last_query();?
Raw Query Example:
select * from table1 where ......
I am struggling with WordPress, and was looking at WP_Query. We usually pass an array of arguments to get result against.
$args = array(
'post_type' => 'post',
'post_per_page' => '2',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'ignore_sticky_posts' => true
);
$the_query = new WP_Query( $args );
Is there any way to print out $the_query in raw form for testing purpose just like we do in CodeIgniter with $this->db->last_query();?
Raw Query Example:
select * from table1 where ......
Share
Improve this question
edited Jul 13, 2017 at 16:27
Morgan Estes
1,55512 silver badges22 bronze badges
asked Jul 13, 2017 at 14:17
mohsinmohsin
1772 silver badges9 bronze badges
1 Answer
Reset to default 4The generated SQL is available via the request property:
echo $the_query->request;
where $the_query is a \WP_Query instance.
Check out how it's formed in the class here.
Also available via the posts_request filter for unsuppressed filtering.
I am struggling with WordPress, and was looking at WP_Query. We usually pass an array of arguments to get result against.
$args = array(
'post_type' => 'post',
'post_per_page' => '2',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'ignore_sticky_posts' => true
);
$the_query = new WP_Query( $args );
Is there any way to print out $the_query in raw form for testing purpose just like we do in CodeIgniter with $this->db->last_query();?
Raw Query Example:
select * from table1 where ......
I am struggling with WordPress, and was looking at WP_Query. We usually pass an array of arguments to get result against.
$args = array(
'post_type' => 'post',
'post_per_page' => '2',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'ignore_sticky_posts' => true
);
$the_query = new WP_Query( $args );
Is there any way to print out $the_query in raw form for testing purpose just like we do in CodeIgniter with $this->db->last_query();?
Raw Query Example:
select * from table1 where ......
Share
Improve this question
edited Jul 13, 2017 at 16:27
Morgan Estes
1,55512 silver badges22 bronze badges
asked Jul 13, 2017 at 14:17
mohsinmohsin
1772 silver badges9 bronze badges
1 Answer
Reset to default 4The generated SQL is available via the request property:
echo $the_query->request;
where $the_query is a \WP_Query instance.
Check out how it's formed in the class here.
Also available via the posts_request filter for unsuppressed filtering.
本文标签: plugin developmentHow to print raw query from WPQuery class just like in CodeIgniter
版权声明:本文标题:plugin development - How to print raw query from WP_Query class just like in CodeIgniter 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749215934a2334161.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论