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

Filter posts under multiple categories?

WordPress does this automatically if you do http://yoursite.com/?cat=1+2 (where 1 and 2 is category ids) OR http://yoursite.com/?category_name=apples+oranges (where apples and oranges is the slugs) OR something like http://yoursite.com/category/apples+oranges

Display “add to cart” button on every listing in product category page?

You can use the WooCommerce hook woocommerce_after_add_to_cart_button. This hook will add content after the “Add To Cart” button. If the customer clicks on this button, the product should get added to the cart, and the customer should be send to the checkout page. Add the below code in your child theme functions.php /* Create Buy … Read more

How to get child categories of a given Post

To get the child categories of a given parent category slug, use a combination of get_category_by_slug() and get_categories(). The latter function will return an array of category objects matching the specified query arguments array; the former will return the ID of a category, given its slug. So, for example: <?php $motorbike_child_cat_args = array( ‘child_of’ => … Read more