Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 8 years ago

#22102 closed defect (bug) (duplicate)

Tags list not displaying programmatically added child tags

Reported by: capcar Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.4.2
Component: Administration Keywords:
Focuses: Cc:



I have an obscure problem in the admin area that may be a bug. I am migrating a site to WordPress, and am creating a number of hierarchical taxonomies programmatically using the wp_insert_term() function. An example:

Parent 1

---child 1

---child 2

Parent 2

---child 3

---child 4

Parent 3

---child 5

---child 6

I am importing these all at once via code on a hidden page. The tags are all being imported correctly, because they are in the database, they are showing up on the "Edit Post" page in their appropriate panel (properly hierarchical), they can be searched for in the tag admin list, and the admin lists the correct number of tags - in this example 9.

HOWEVER, when I go to the admin tag list, this is the only thing that shows:

Parent 1

---child 1

---child 2

Parent 2

Parent 3

..and yet the the admin lists 9 tags as being in the system. Troubleshooting this, I discovered that if import the children tags separately and REFRESH THE TAG LIST between each import, then the list will show up correctly.

Here's another twist: If I import enough tags to span multiple admin pages (i.e. page 1 of 10), and the last 5 pages are children tags of, in this example, Parent 3... then Wordpress will display 5 empty pages for the list of tags. It clearly knows how many pages are needed for the tags, but it is not displaying them.

I have tested this with the default categories as well as custom taxonomies (hierarchical), and can recreate the problem over and over. This leads me to believe that there is a bug in how WordPress refreshes the tag list - clearly it is not generating this list directly from the database, because those tags are there. Is this list being cached somewhere?

Obscure problem, I know, but hopefully this might ring a bell with someone.

Change History (9)

#1 @SergeyBiryukov
9 years ago

Some code (as simple as possible) to reproduce the issue would be helpful.

#2 @capcar
9 years ago

I'm grabbing keywords from an MSSQL database ($conn) and making them child tags of a set of tags I've set up manually in Wordpress (those are the ID numbers in the functions). Here's the basic code:


function import_keywords($conn,$legacyparent,$parent) {
	if ($conn) {
		$query = "Select * from Keyword where KeywordCategory = '" . $legacyparent . "'";
		$result = odbc_exec($conn,$query);
		echo '<p>Getting keywords for <b>' . $legacyparent . '</b>:<br />';
					$term = odbc_result($result,"KeywordText");
					wp_insert_term ($term,'post_tag',array('parent'=> $parent));
					echo '&nbsp;&nbsp;&nbsp;Keyword: <strong>' . $term . '</strong> inserted as child of <strong>' . $legacyparent . '</strong><br />';
			odbc_close ($conn);
		} else {
			echo "odbc not connected";

The reproducible problem is that if I run all 5 of those functions at once, then the child keywords of the last 4 functions will not appear in the admin menu (even though they are in the database). However, if I run each function independently and refresh the admin menu between each one, then they all appear.

Last edited 9 years ago by capcar (previous) (diff)

#3 @capcar
9 years ago

One thing to note is that in this situation, I've altered the default 'post_tag' taxonomy to be hierarchical in my functions file:

			array( 'post','page' ),
				'hierarchical' => true,
				'labels' => array(
					'name' 			=> _x('Tags', 'taxonomy general name'),
					'singular_name' 	=> _x('Tag', 'taxonomy general name'),
					'search_items' 	=> __('Search Tags'),
					'popular_items' 	=> __('Popular Tags'),
					'all_items' 		=> __('All Tags'),
					'parent_item' 		=> __('Parent Tag'),
					'parent_item_colon' => __('Parent Tag:'),
					'edit_item'		=> __('Edit Tag'),
					'update_item' 		=> __('Update Tag'),
					'add_new_item' 	=> __('Add New Tag'),
					'new_item_name' 	=> __('New Tag Name')
				'query_var' => 'tag',
				'rewrite' => array( 'slug' => 'post_tag' ),

If I switch it back to non-hierarchical, then all tags appear properly in the admin menu.

Last edited 9 years ago by capcar (previous) (diff)

#4 @capcar
9 years ago

I just discovered that if you edit and save any keyword once, then all of the missing keywords will finally appear on the list. The problem does seem to be that "wp_insert_term" is missing a step when regenerating the Tag list. It's above my head to determine where that step is, however.

#5 @tarasm
9 years ago

I encountered this problem several time as well. I'm looking for a solution for it right now.

#6 @tarasm
9 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #14485.

#7 @ocean90
8 years ago

  • Milestone Awaiting Review deleted

#8 @ZaneMatthew
8 years ago

  • Cc zanematthew@… added

I've ran into this issue more than one, have yet to find a solutions.

#9 @ZaneMatthew
8 years ago

This snippet from the ticket listed above did the fix

if ( taxonomy_exists( 'my-term' ) ) {
    wp_cache_set( 'last_changed', time( ) - 1800, 'terms' );
    wp_cache_delete( 'all_ids', 'my-term' );
    wp_cache_delete( 'get', 'my-term' );
    delete_option( "my-term_children" );
    _get_term_hierarchy( 'my-term' );
Note: See TracTickets for help on using tickets.