There is no wp-cli command to delete a post by title, but you could easily roll your own.
Adding something like this in you current themes function.php file would work:
if (defined('WP_CLI') && WP_CLI) {
class CYCLONECODE_WP_CLI_COMMANDS extends WP_CLI_Command
{
/**
* Delete post by title.
*
* ## OPTIONS
*
* <title>
* : The title of the post you would like to delete.
*
* [--type=<type>]
* : The post type.
* [--force-delete]
* : Deletes the post without moving it to trash.
*
* ## EXAMPLES
*
* wp post deleteByTitle "Hello world"
*
* @when after_wp_load
*/
function deleteByTitle($args, $assoc_args)
{
global $wpdb;
list($title) = $args;
$type = $assoc_args['type'] ?? 'post';
$force_delete = $assoc_args['force-delete'] ?? false;
$result = $wpdb->get_results(
$wpdb->prepare("SELECT ID FROM $wpdb->posts
WHERE post_type = %s &&
post_status="publish" &&
post_title = %s",
$type, $title)
);
if ($result) {
wp_delete_post($result[0]->ID, $force_delete);
}
}
}
WP_CLI::add_command('post', 'CYCLONECODE_WP_CLI_COMMANDS');
}
You should then be able to use the command like this:
wp post deleteByTitle "Hello world"
wp post deleteByTitle "foo" --type="custom_post_type"
wp post deleteByTitle "bar" --force-delete
You could also first make a query using wp-cli and then use the returned ID to then execute a post delete
command:
wp post delete $(wp db query \
'SELECT ID \
FROM wp_posts \
WHERE post_title = "POST_TITLE" && post_status="publish" && post_type="post"' \
--skip-column-names \
)
In the above you will need to replace POST_TITLE
with the title of the post you would like to delete.