WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Form Post Action: Pre-inserted post should not assign the WordPress default category #140

@mcaskill

Description

@mcaskill

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):

  1. Create a Form with a Post Action that creates a new post of a post type that is not associated with the category taxonomy, such as page.
  2. Submit the form to create a new post of that post type.
  3. Check the wp_term_relationships table 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions