When using the Gutenberg Block Editor the normal hooks for saving a post don't have the same behavior as with the classic editor.
pre_post_update
save_post
wp_insert_post
For example, if you hook into the save_post
-hook the $permalink
and the $categories
will not return the new value, but instead the old value. Which is not the behavior that I expected from the classic editor.
add_action( 'save_post', 'custom_save_post', 10, 3 );
function custom_save_post( $post_id, $post, $update )
{
$permalink = get_permalink( $post_id );
$categories = get_the_terms( $post_id, 'category' );
}
How can I make it work so that I can retrieve the pre-updated permalink and the post-updated permalink?
When using the Gutenberg Block Editor the normal hooks for saving a post don't have the same behavior as with the classic editor.
pre_post_update
save_post
wp_insert_post
For example, if you hook into the save_post
-hook the $permalink
and the $categories
will not return the new value, but instead the old value. Which is not the behavior that I expected from the classic editor.
add_action( 'save_post', 'custom_save_post', 10, 3 );
function custom_save_post( $post_id, $post, $update )
{
$permalink = get_permalink( $post_id );
$categories = get_the_terms( $post_id, 'category' );
}
How can I make it work so that I can retrieve the pre-updated permalink and the post-updated permalink?
Share Improve this question edited Feb 29, 2020 at 18:00 Mark asked Feb 28, 2020 at 17:14 MarkMark 1,0291 gold badge15 silver badges27 bronze badges 10 | Show 5 more comments1 Answer
Reset to default 3When using the Gutenberg Block editor you need to use different hooks to get the expected behavior.
rest_insert_{$this->post_type}
The pre-update hook.rest_after_insert_{$this->post_type}
The post-update hook.
credits: @SallyCJ
permalink.txt
and the correct/updated category objects dump incategories.txt
andterms.txt
. So I didn't need to proceed to the fourth step (editing the coretaxonomy.php
file). Are you using the latest WordPress stable release? Have you tested on other hosts? This might be something specific to your host/server.. – Sally CJ Commented Feb 28, 2020 at 18:13Ctrl + Shift + I
then go to the Network tab and just check the relevant requests. In fact, the console might be able to tell you what's going on with the button getting stuck.. – Sally CJ Commented Feb 28, 2020 at 21:42