Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Keep current status for a question when it is updated #7603
Keep current status for a question when it is updated #7603
Changes from 2 commits
c6682c5
d663017
969082e
bfd0375
738b566
94c11d9
485caf5
d9655ee
269be0d
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! Solution works perfectly as expected! 🚀
I was just thinking of another solution and wanted to share with you.
Looks like this is a known issue caused by using
wp_insert_post
for updating posts instead ofwp_update_post
https://developer.wordpress.org/reference/functions/wp_insert_post/#comment-5150.So I was just wondering, instead of fetching the
status
manually here and re-assigning it, do you think it'd be a better and more understandable solution to use thewp_update_post
function when we are actually just updating the post? An added advantage will be, we'll be using the right function for the right job.So we just remove the line above and we replace Line 199 with something like
$result = $is_new ? wp_insert_post( $post_args ) : wp_update_post( $post_args );
.WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Imran92!
Yes, it makes sense for the sake of simplicity.
Thinking about it further, I see a little sense of using a ternary. We can simply use
wp_update_post
(wp_update_post
callswp_insert_post
under the hood).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here: 969082e
It isn't that important for the question category, but updated it for consistency: bfd0375