WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#23530 closed defect (bug) (duplicate)

Attachment taxonomies, $term->count not working

Reported by: paddelboot Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

Backend:

  1. Register an attachment taxonomy
  2. Create a taxonomy term
  3. Upload an attachment and check the box of the newly created term, save.
  4. Go to the attachment taxonomie's overview
  5. Under "Media", it shows 0
  6. Click on "0", and you should see the attachment in the overview.

Code:

register_taxonomy( 'attachment_directories', 'attachment' );

$term = wp_insert_term( 'parent', 'attachment_directories' );

$args = array(
			'post_title' => 'dummy-attachment',
			'post_content' => '',
			'post_status' => 'inherit',
			'post_mime_type' => 'image/jpeg',
			'post_author' => '1'
		);

$id = wp_insert_attachment( $args );

wp_set_object_terms( $id, $term[ 'term_id' ], 'attachment_directories' );

$args = array(
			'hide_empty' => TRUE,
			'fields' => 'ids'
		);

$non_empty_directories = get_terms( 'attachment_directories', $args );

//$non_empty_directories is an empty array(), but it should return the ID of the 'parent' term.

Change History (6)

comment:1 @paddelboot2 years ago

  • Cc ms@… added

comment:2 @paddelboot2 years ago

Of course last line should be:

$non_empty_directories = get_terms( 'attachment_directories', $args );

instead of:

$non_empty_directories = get_terms( 'attachment_directories', $args3 );

comment:3 @paddelboot2 years ago

It seems to have something to do with whether the attachment is attached to a post or other object or not.

  • Editing an unattached media file and selecting a taxonomy term for it does not, after saving, increase this term's counter
  • Un-selecting the taxonomy term, saving the media file, attaching the media file to something, and again selecting the taxonomy tag does, after saving, increase the term's counter

Is this in any way wanted?

comment:4 @SergeyBiryukov2 years ago

  • Component changed from General to Taxonomy
  • Description modified (diff)

comment:5 @SergeyBiryukov2 years ago

  • Description modified (diff)

comment:6 @SergeyBiryukov2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #22558.

Note: See TracTickets for help on using tickets.