Make WordPress Core

Opened 10 months ago

Last modified 10 months ago

#59215 new defect (bug)

Bug in wp_set_post_categories function

Reported by: faaiq's profile 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 sabernhardt)

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 @sabernhardt
10 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.

10 months ago

  • Keywords has-patch added

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

#3 @SergeyBiryukov
10 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.

  1. Could you provide the steps to reproduce the issue on a clean install?
  2. wp_set_post_categories() is indeed specific to categories by design. Perhaps wp_set_post_terms() would work for your use case?
Version 0, edited 10 months ago by SergeyBiryukov (next)
Note: See TracTickets for help on using tickets.