Get WooCommerce product category list in functions.php

You need to use action to get categories. in init action you can get product categories. add_action(‘init’, ‘my_product_cat’); function my_product_cat() { $woo_cat_args = array( ‘taxonomy’ => ‘product_cat’, ‘orderby’ => ‘name’, ‘hide_empty’ => 0, ); $woo_categories = get_categories( $woo_cat_args ); echo “<pre>”; print_r($woo_categories); echo “</pre>”; }

What is the use case for sharing a term between multiple taxonomies?

The helpful folks on WordPress IRC pointed me to this article, which answered my question: https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/ In WordPress 4.2, shared taxonomy terms – those items in the wp_terms table that are shared between multiple taxonomies – will be split into separate terms when one of the shared terms is updated. This change (31418) fixes one … Read more

How to associate custom taxonomy terms with custom post type?

$catids = $_POST[‘artticle_category’]; /* * If the ids are coming from the database or another source, we would * need to make sure these were integers or convert them to interger using intval: */ $catids = array_map( ‘intval’, $catids ); $catids = array_unique( $catids ); $taxonomy = ‘articles_category’; $post_id = ‘1’; $term_taxonomy_ids = wp_set_object_terms( $post_id, … Read more

Create category after theme setup and modify the default one

You can use wp_update_term to modify terms (even the default uncategorized) and wp_insert_term to update existing terms. Here is a basic example that should get you there. function add_category(){ // Update Uncategorized Category (1) wp_update_term( 1, ‘category’, array( ‘name’ => ‘New Category Name’, ‘slug’ => ‘new-category-slug’ ) ); // Insert New Category if(!term_exists(‘another-category’)) { wp_insert_term( … Read more