Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot update date when updating status to 'publish' #427

Closed
2 tasks done
adekbadek opened this issue Feb 8, 2021 · 1 comment · Fixed by #428
Closed
2 tasks done

Cannot update date when updating status to 'publish' #427

adekbadek opened this issue Feb 8, 2021 · 1 comment · Fixed by #428

Comments

@adekbadek
Copy link

Bug Report

Describe the current, buggy behavior

When setting a post's status to 'publish', while also setting a date, the passed date is ignored and the current date is set.

Describe how other contributors can replicate this bug

  • wp post create --post_title='test'
  • wp post update <ID> --post_date='2005-01-24T09:52:00.000Z' --post_status='publish'
  • wp post get <ID> --field=post_date 👉 observe the date is current date

Describe what you expect as the correct outcome

I expect the to be able to set the post date while changing post status to 'publish'

Let us know what environment you are running this on

OS:	Linux 4.19.0-12-amd64 wp-cli/wp-cli#1 SMP Debian 4.19.152-1 (2020-10-18) x86_64
Shell:	/bin/bash
PHP binary:	/usr/local/php7.4/bin/php
PHP version:	7.4.14
php.ini used:	/usr/local/php7.4/conf/php.ini
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/srv/htdocs
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version:	2.4.0
@danielbachhuber
Copy link
Member

Thanks for the report, @adekbadek

As it turns out, you're running into some undocumented behavior of wp_update_post(). Specifically, if you're publishing a post and updating its date at the same time, you need to also include --edit_date=1:

wp post update <ID> --post_date='2005-01-24T09:52:00.000Z' --post_status='publish' --edit_date=1

I don't think we should deviate from core behavior in this case. But, we can add a test case to WP-CLI to document the behavior: #428

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants