I'm trying to use get_posts( $args ) to get some custom post types. Is there a way to see the mysql query generated by the get_posts function?


1 Answer 1


Thank you to Tom J Nowell for pointing me to using WP_Query instead of get_posts. With WP_Query you have the entire WP_Query object to reference. So something like the following gives the actual mysql query of the args I was using.

// these same args also worked with get_posts()
$args = array(
    'post_type' => 'post',
    'order' => 'ASC',
    'post_status' => 'publish',

// create a new WP_Query object with the args above
$the_object = new WP_Query($args);

// show the mysql as a string
echo $the_object->request;

// see EVERYTHING in the WP_Query object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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