miniMAC miniMAC - 1 year ago 102
PHP Question

How to var dump each posts when moving to trash in wordpress

I'm trying to show a list of posts inside a var_dump, this is the actual code:

function deleted_cpt_orders() {

global $post_type, $post;

if ( $post_type == 'cpt_orders' ) {



add_action( 'trashed_post', 'deleted_cpt_orders' );

If i delete only 1 post the
is shown, but if i delete 2 posts or more the result is


Answer Source

global $post is supposed to hold a single post object. If you delete multiple objects, it won't be set. However, trashed_post hook passes post id, therefore, you can do the following

function deleted_cpt_orders($object_id)
    $post = get_post($object_id);
    if ($post->post_type == 'cpt_orders')

add_action('trashed_post', 'deleted_cpt_orders');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download