You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking at the official WP documentation here, the wp post delete command should be able to take a subcommand to list all the IDs to delete.
This works well on a Linux like system, but doesn't on Windows Powershell.
I know that it is more a Windows+Powershell issue, but that would be nice if we could find a workaround solution for this.
Expectations
# Delete all pages
$ wp post delete $(wp post list --post_type='page' --format=ids)
Success: Trashed post 1164.
Success: Trashed post 1186.
Reality
# Delete all pages
$ wp post delete $(wp post list --post_type='page' --format=ids)
Success: Trashed post 1164 1186.
In that case, post id 1186 has not been deleted because the subcommand result is interpreted as a single string parameter given to the delete command.
The \WP_CLI\CommandWithDBObject::_delete function that should receive $args as an array of IDs receive in reality one string param with the value 1164 1186 which evaluates as 1164 when casted to integer.
Function parameters type hint
Moreover, the wp_delete_post() function that is called underneath, should receive an integer value as first parameter.
/** * @param int $postid Optional. Post ID. Default 0. * @param bool $force_delete Optional. Whether to bypass Trash and force deletion. * Default false. * @return WP_Post|false|null Post data on success, false or null on failure. */functionwp_delete_post( $postid = 0, $force_delete = false ) {}
/** * Filters whether a post deletion should take place. * * @since 4.4.0 * * @param WP_Post|false|null $delete Whether to go forward with deletion. @TODO description * @param WP_Post $post Post object. * @param bool $force_delete Whether to bypass the Trash. */$check = apply_filters( 'pre_delete_post', null, $post, $force_delete );
I don't know if parameters hints will be enforced later, but there might be an issue there too as this function and the hooks triggered are all expecting an integer value.
The text was updated successfully, but these errors were encountered:
I moved this issue to wp-cli/wp-cli because I think it's related to how arguments are passed/parsed on Powershell. Here's some past work on PowerShell compatibility, if it's helpful: https://github.com/ericmann/WP-PowerShell
Can you share wp cli info ?
Also, what happens when you run wp post delete 1164 1186? Do you see the same error as wp post delete $(wp post list --post_type='page' --format=ids) ?
As a point of reference, here's where WP-CLI reads $GLOBALS['argv']:
I faced the same problem and put together such a solution:
cd G:\serverl6\www\wp-test.edit
# 1 option, fast, but you can't transfer a lot of ids$ids=$(wp post list --post_type='guides'--format=ids --posts_per_page=1000)
$ids=$ids.Split("")
wp post delete $ids--force
<## Option 2, slow, but you can transfer an unlimited number of ids$ids = $(wp post list --post_type='guides' --format=ids)$numbers = $ids.Split(" ")foreach ($id in $numbers) { wp post delete $id --force}#>Read-Host-Prompt "Press Enter to exit"
Looking at the official WP documentation here, the
wp post delete
command should be able to take a subcommand to list all the IDs to delete.This works well on a Linux like system, but doesn't on Windows Powershell.
I know that it is more a Windows+Powershell issue, but that would be nice if we could find a workaround solution for this.
Expectations
Reality
In that case, post id
1186
has not been deleted because the subcommand result is interpreted as a singlestring
parameter given to thedelete
command.The
\WP_CLI\CommandWithDBObject::_delete
function that should receive$args
as an array of IDs receive in reality one string param with the value1164 1186
which evaluates as1164
when casted to integer.Function parameters type hint
Moreover, the
wp_delete_post()
function that is called underneath, should receive an integer value as first parameter.I don't know if parameters hints will be enforced later, but there might be an issue there too as this function and the hooks triggered are all expecting an integer value.
The text was updated successfully, but these errors were encountered: