Match and Merge Terms in Different Taxonomies

Grab all the post tags and loop over them. If it’s deemed an “author” by a pattern match, check to see if the equivalent author_tax term exists. If not, create it. Now you can build two stacks: one for author_tax terms to append to the post, and another for post_tag‘s to be removed. $post_tags = … Read more

Style a category from category list

You can try looping to match the category name you need. $categories = get_the_category(); $category_name=”foo1″; // set this to the category name you want to show $output=””; if($categories){ foreach($categories as $category) { if ( $category_name == $category->cat_name) { $output .='<div class=”category-custom-class”>’.$category->cat_name.'</div>’; } else { $output .='<div class=”category-custom-class1″>’.$category->cat_name.'</div>’; } } echo $output; }

Copy/Move selected taxonomy terms to another taxonomy for posts

This will get all posts with $old_tax, copy the terms from $old_tax to $new_tax, and then set the $new_tax terms for those posts. <?php function convert_tax($old_tax, $new_tax) { $pages = get_posts(array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => $old_tax, ‘operator’ => ‘EXISTS’ ) ) )); foreach($pages as $post) { $terms … Read more

Illegal string offset ‘taxonomy’ in

Most likely the problem comes from: $terms = get_the_terms( $post->ID, $args[‘taxonomy’] ); i.e. you have to make sure it’s not false or WP_Error object. You should also check the output of: var_dump( $args ); Try for example: if( ! is_array( $terms ) ) return $output; or if( ! $terms || is_wp_error( $terms ) ) return $output; … Read more

Retrieve list of taxonomies in json

Your problem is that your trying to access taxonomy data before it is registered. This doesn’t work: add_action(‘init’, ‘json_handler’); function json_handler(){ $categories = get_terms( ‘my_cat’, ‘orderby=count&hide_empty=0’ ); if( ! is_wp_error( $categories ) ) { // encode the $categories array as json print_r( json_encode( $categories ) ); } } add_action(‘init’, ‘create_stores_nonhierarchical_taxonomy’); function create_stores_nonhierarchical_taxonomy() { // Labels … Read more