On one of the projects I’m working on, we have a feed which is being aggregated into WordPress. The feed items are being assigned ot a custom post type and a custom taxonomy.
New terms are created and assigned to posts succesfully, and show on the frontend and in the post edit screens. However if I go to the taxonomies page in the backend, it lists only the terms that were present prior. If I create a new term e.g. ‘Bob’ and then refresh the page, all the terms appear as expected.
Clearly there is a cache or transient of some kind or a hook that needs to be fired, something that is not happening when I create the taxonomy terms programatically, but IS happening when I do it via the backend.
Any clues?
edit:
Here’s the code:
$product_group = ! empty( $custom_meta[ 'product_group' ] ) ? $custom_meta[ 'product_group' ] : false;
$product_type = ! empty( $custom_meta[ 'product_type' ] ) ? $custom_meta[ 'product_type' ] : false;
if ( $product_group && $product_type ) {
$tax = strtolower( $product_group ) == 'opinion' ? 'category' : 'product_categories';
if ( ! ( $group = term_exists( $product_group, $tax ) ) )
$group = wp_insert_term( $product_group, $tax, array( 'description' => $product_group ) );
$group_id = ! is_wp_error( $group ) && isset( $group[ 'term_id' ] ) ? $group[ 'term_id' ] : 0;
if ( ! ( $type = term_exists( $product_type, $tax ) ) )
$type = wp_insert_term( $product_type, $tax, array( 'description' => $product_type, 'parent' => $group_id ) );
$type_id = ! is_wp_error( $type ) && isset( $type[ 'term_id' ] ) ? $type[ 'term_id' ] : 0;
$the_term = get_term_by( 'id', $type_id, $tax );
$taxonomies = array( $tax => array( $the_term->slug ) );
}
It seems to be only the children that don’t show up
Try
clean_term_cache();
clean_object_term_cache();