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 ......
The 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.