Wordpress - Delete custom-post-type post

admin

Administrator
Staff member
I am trying to add a button in wordpress that deletes a custom-post-type post with a specific title and current user as author.

Problem that occurring is that all the posts gets deleted, all the job_alert posts, not only for this specific author or with this title.

Can someone see why?

Code:
$delete_post = array(
    'post_type'     => 'job_alert',
    'post_title'    => $title,
    'post_status'   => 'publish',
    'post_author'   => $current_user->ID
);
    $posts = new WP_Query( $delete_post );

if ( $posts->have_posts() ) {
    while ( $posts->have_posts() ) {
        $posts->the_post();
         wp_delete_post( get_the_ID());
    }
}

I also have this code that creates a post and that works great. Similar code.

Code:
$new_post = array(
    'post_type'     => 'job_alert',
    'post_title'    => $title,
    'post_status'   => 'publish',
    'post_author'   => $current_user->ID
);

$post_id = wp_insert_post( $new_post );