Assign parent category to all posts that are already assigned to child category

be careful and only run it once $_query = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => -1, ) ); function complete_parent_category( $term_id, $dep=array() ) { $category = get_term( $term_id, ‘category’ ); $dep[ $category->term_id ] = $category->slug; if( $category->parent ) { $dep = complete_parent_category( $category->parent, $dep ); } return $dep; } echo ‘<pre>’; while( $_query->have_posts() … Read more

Custom color for each category name

To achieve this Follow these easy step: Add field for color To Add/Edit category Screen using hooks category_add_form_fields and category_edit_form_fields add_action(‘category_add_form_fields’, ‘my_category_fields’, 10, 2); add_action(‘category_edit_form_fields’, ‘my_category_fields’, 10, 2); function my_category_fields($term) { $cat_color = get_term_meta($term->term_id, ‘cat_color’, true); if($cat_color == ”) $cat_color=”#000000″; // Default black color ?> <tr class=”form-field”> <th valign=”top” scope=”row”><label for=”cat_color”><?php _e(‘Color code’); ?></label></th> <td> … Read more

Remove child products from woocommerce category page [closed]

you want to display only parent category products and remove the child category products. Add the following lines of code at the end of your theme’s functions.php file. function exclude_product_cat_children( $wp_query ) { if ( isset( $wp_query->query_vars[‘product_cat’] ) && $wp_query->is_main_query() ) { $wp_query->set( ‘tax_query’, array( array ( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => … Read more

Highlight current category in wp_list_categories

This will add a current-cat class to any / all categories connected to the post, not jut one. Add this to functions.php function tax_cat_active( $output, $args ) { if(is_single()){ global $post; $terms = get_the_terms( $post->ID, $args[‘taxonomy’] ); foreach( $terms as $term ) if ( preg_match( ‘#cat-item-‘ . $term ->term_id . ‘#’, $output ) ) $output … Read more

Create a full width responsive header image per page

John there are lots of ways to do this, depending on what you want exactly and how much experience you have with html/php/css (or how much time you’d want to spend learning). There are plenty of plugins on wordpress that could achieve this. You might want to just try some of them out: https://wordpress.org/plugins/search.php?q=custom+header If … Read more

Update term count using a callback function

I think I’ve worked this out. First of all, you need to define your taxonomy. I’m pulling this code directly from the codex; however, I’ve added one parameter update_count_callback. I’ve set this to the cleverly titled my_update_count_callback. This just specifies that when a post of type post (this will be whatever CPTs you associate the … Read more