-
Notifications
You must be signed in to change notification settings - Fork 29
Description
Describe the bug
When Post Action pre-inserts a post, WordPress defaults to post type post which in turn defaults to assigning the default_category if defined.
If the inserted post is of a post type that is not associated with the category taxonomy, the relationship between the inserted post and the default category is never purged.
To Reproduce
On an installation of WordPress that has a default_category (see wp_options table):
- Create a Form with a Post Action that creates a new post of a post type that is not associated with the
categorytaxonomy, such aspage. - Submit the form to create a new post of that post type.
- Check the
wp_term_relationshipstable to see the new post is assigned to the default category.
Expected behavior
I would expect that if the new post—not associated with the category taxonomy—to not have any relationships.
Proposed solution
The pre-inserted post should use the post status auto-draft to bypass the default category logic.
For the project I'm currently working on I am using this hook:
add_action( 'acfe/form/submit_post/action=save_custom_post', function ( int $post_id ) : void {
wp_delete_object_term_relationships( $post_id, 'category' );
}, 10, 1 );WordPress & ACF
WordPress version: 6.7.1
ACF Pro version: 6.3.12
ACF Extended Pro version: 0.9.1