[wp-trac] [WordPress Trac] #50080: wp_set_post_tags() adds terms to post types that don't support the term's taxonomy

WordPress Trac noreply at wordpress.org
Mon May 4 16:23:52 UTC 2020


#50080: wp_set_post_tags() adds terms to post types that don't support the term's
taxonomy
---------------------------+-----------------------------
 Reporter:  paulschreiber  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Taxonomy       |    Version:  5.4
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Setup:

 (1) Register a custom post type without taxonomy support
 {{{#!php
 add_action( 'init', function() {
         register_post_type(
                 'foobar',
                 [
                         'labels'        => [
                                 'name'          => __( 'foobars' ),
                                 'singular_name' => __( 'foobar' ),
                         ],
                         'public'             => false,
                         'publicly_queryable' => true,
                         'has_archive'        => false,
                         'hierarchical'       => false,
                 ]
         );
 } );
 }}}

 (2) Create a tag
 {{{#!php
 wp_insert_term( 'green', 'post_tag' );
 => array(2) {
   ["term_id"]=>
   int(4)
   ["term_taxonomy_id"]=>
   int(4)
 }
 }}}

 (3) Create a post
 {{{#!php
 wp_insert_post( [ 'post_type' => 'foobar' ] );
 => int(8)
 }}}

 (4) Assign the term to the post
 {{{#!php
 wp> wp_set_post_tags( 8, 'green' );
 => array(1) {
   [0]=>
   string(1) "4"
 }
 }}}

 Expected behaviour is a `WP_Error` object, since the CPT `foobar` does not
 support the `post_tag` taxonomy.

 (5) Get the tags for the post
 {{{#!php
 wp> wp_get_post_tags(8)
 => array(1) {
   [0]=>
   object(WP_Term)#1955 (10) {
     ["term_id"]=>
     int(4)
     ["name"]=>
     string(5) "green"
     ["slug"]=>
     string(5) "green"
     ["term_group"]=>
     int(0)
     ["term_taxonomy_id"]=>
     int(4)
     ["taxonomy"]=>
     string(8) "post_tag"
     ["description"]=>
     string(0) ""
     ["parent"]=>
     int(0)
     ["count"]=>
     int(1)
     ["filter"]=>
     string(3) "raw"
   }
 }
 }}}

 Expected behaviour is an empty array.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50080>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list