Opened 16 months ago
Last modified 16 months ago
#59215 new defect (bug)
Bug in wp_set_post_categories function
Reported by: | faaiq | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.3 |
Component: | Taxonomy | Keywords: | has-patch reporter-feedback |
Focuses: | Cc: |
Description (last modified by )
wp_set_post_terms( $post_id, $post_categories, 'category', $append );
category is being passed staticky. so wp_set_post_categories
is not working to map custom category with custom post type. it is not making any entry for custom post type in the table wp_term_relationships
.
Change History (3)
#1
@
16 months ago
- Component changed from General to Taxonomy
- Description modified (diff)
- Keywords changes-requested removed
This ticket was mentioned in PR #5102 on WordPress/wordpress-develop by @nihar007.
16 months ago
#2
- Keywords has-patch added
#3
@
16 months ago
- Keywords reporter-feedback added
Hi there, welcome to WordPress Trac! Thanks for the ticket.
Looking at the PR, it does not appear to be correct (as demonstrated by the failing unit tests), because the third parameter of wp_set_post_terms()
is the taxonomy name, not the post type. Looking further, the post type does not seem relevant at all, since the underlying wp_set_object_terms()
does not use it, only the post ID.
so
wp_set_post_categories
is not working to map custom category with custom post type.
- Could you provide the steps to reproduce the issue on a clean install?
wp_set_post_categories()
is indeed specific to categories by design. Perhapswp_set_post_terms()
would work for your use case?
In the wp_set_post_categories function in the wp-includes/post.php file.
Before update:
return wp_set_post_terms( $post_id, $post_categories, 'category', $append );
After update:
return wp_set_post_terms( $post_id, $post_categories, $post_type, $append );
Trac ticket: 59215