Sanitize and Save metabox values
Sanitize and Save metabox values
Sanitize and Save metabox values
I had the same problem and solved it by replacing if( !current_user_can( ‘edit_post’ ) ) return; by: if ( !current_user_can(‘edit_post’, $post_id) ) return;
This issue shouldn’t happen if you’re using the classic editor, however, if you’re using the block/Gutenberg editor which uses the REST API, then that issue can be fixed by using the wp_after_insert_post hook instead. Excerpt from https://make.wordpress.org/core/2020/11/20/new-action-wp_after_insert_post-in-wordpress-5-6/: The new action wp_after_insert_post has been added to WordPress 5.6 to allow theme and plugin developers to run … Read more
Of course it never changes, because you told it that it never changes: // Selected page list const { initialSelectedPages, selectedPagesResolved} = useSelect( ( select) => { …. }, —–>[] <—– ); You declared the dependencies as an empty array, and empty arrays won’t change, so this hook won’t update when your attributes update because … Read more
Well because your code seems like to be bugy/not full – i wrote my code. This will add one meta box with one text field in post (you can change it to be added in your custom post_type)- Post title. Also i had to use QUERY to update/add title, because i can not find any … Read more
The post_category needs to be passed as an array of category IDs (even if you’re only adding one category). Try this: $post_data[“post_category”] = array( $catslug->ID );
First of: Your custom title suffix getting duplicated might not be what you want to happen, but is expected behavior as per your code sample. The save_post action hook runs everytime a post (or page) is created or updated. Hence your callback runs everytime. Let me offer two solutions: 1 Use the wp_insert_post action instead … Read more
If you suspect content-specific issue, I’d first try to start with clean site and set of test content instead ( official Theme Unit Test data for example). If processing content is indeed at fault this is quite unusual issue. If you can narrow it down to specific function it might be possible to build some … Read more
I think the batter way is to use plugin. Check this : http://wordpress.org/extend/plugins/search.php?q=form&sort= I personally suggest you Contact Form 7 Just past form plugin short code in your page/post , that’s it ! Cheers !
I was trying to set the Core post-thumbnail. I found my issue. I was running the function: delete_post_meta($post_id, ‘_thumbnail_id’), before I would set_post_thumbnail($post_id,$thumb_id); Apparently even though the delete was in the code before it still caused it to delete it from the DB. Very strange… I had it in there as I was worried I … Read more