How to get product count with respect to categories in WooComerce

You just need to add $cat->count to get the count of all products in that category. Hope this helps you out. $args = array( ‘number’ => $number, ‘orderby’ => $orderby, ‘order’ => $order, ‘hide_empty’ => $hide_empty, ‘include’ => $ids ); $product_categories = get_terms( ‘product_cat’, $args ); foreach( $product_categories as $cat ) { echo $cat->name.’ (‘.$cat->count.’)’; … Read more

Replace category titles

Well thank you for this question i did this after you posted this function category_title( $title ){ if( is_category(‘name1’) ){ $title=”name1 title”; }elseif( is_category(‘name2’) ){ $title=”name2 title”; } return $title; } add_filter( ‘get_the_archive_title’, ‘category_title’ ); Hope this helps

If category is in parent category?

If i understand right your “post_is_in_descendant_category” function checks if a post is descendant of a category and you want to check if a category is descentand. If so the add this function to your functions.php function is_desc_cat($cats, $_post = null) { foreach ((array)$cats as $cat) { if (in_category($cat, $_post)) { return true; } else { … Read more

How to get post category title within the loop?

The function get_the_category() returns an array of category objects. To get the name of the first category, use this: $categories = get_the_category(); $cat_name = $categories[0]->cat_name; For a list of the properties of the category object, see the documentation on get_the_category()

Make parent category not selectable when it has child categories

I disabled the parent boxes to avoid shifting parents to the left. add_action( ‘admin_footer-post.php’, ‘wpse_98274_disable_top_categories_checkboxes’ ); add_action( ‘admin_footer-post-new.php’, ‘wpse_98274_disable_top_categories_checkboxes’ ); /** * Disable parent checkboxes in Post Editor. */ function wpse_98274_disable_top_categories_checkboxes() { global $post_type; if ( ‘post’ != $post_type ) return; ?> <script type=”text/javascript”> jQuery( “#category-all ul.children” ).each( function() { jQuery(this).closest( “ul” ).parent().children().children( “input” ).attr( … Read more

Add class to items in wp_list_categories()

Yes, it is possible. wp_list_categories accepts a (custom) walker that may handle this. Put the following in your functions.php file: class Custom_Walker_Category extends Walker_Category { function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { extract($args); $cat_name = esc_attr( $category->name ); $cat_name = apply_filters( “list_cats’, $cat_name, $category ); $link = … Read more

How do you bulk remove a category from posts?

You can make use of wp_remove_object_terms() to remove the desired category from a post. What we will do is, run a custom query to get all the post with the associated category, and then loop through the posts and use wp_remove_object_terms() to remove the category FEW NOTES: The code is untested and might be buggy. … Read more

Why is get_the_category() saying that I have two categories?

I’m guessing you’re referring to the [category_count] => 2 when you say “saying that I have two categories”? If so, you should understand that category_count is not the number of cateogries that this post has, but rather it is ‘the number of uses of this category (also stored as ‘count’)’ – see get_the_category function reference. … Read more