How can I duplicate categories and tags?

add_action( ‘save_post’, ‘add_tag_based_on_category’ ); function add_tag_based_on_category( $post_id ) { $args = array( ‘fields’ => ‘names’ ); $categories = wp_get_post_categories( $post_id, $args ); $cat_names = implode( ‘, ‘, $categories ); wp_set_post_tags( $post_id, $cat_names, true ); }

Additional featured post on first page

If I understand your goal correctly, I would create two queries. The first will retrieve only the featured post. We’ll display that post on the first page only and store its ID to use later. Then, a second query will get all of the remaining posts. // first query to retrieve the featured post $featured_post_id … Read more

force category base – archive pages work WITH & WITHOUT category base slug in url?

I found a solution here: 404 on category.php pagination So, to fix my issue I just needed to add these custom rewrite rules to functions.php: add_action( ‘init’, ‘wpa58471_category_base’ ); function wpa58471_category_base() { add_rewrite_rule( ‘blog/([^/]+)/page/(\d+)/?$’, ‘index.php?category_name=$matches[1]&paged=$matches[2]’, ‘top’ ); add_rewrite_rule( ‘blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$’, ‘index.php?category_name=$matches[1]&feed=$matches[2]’, ‘top’ ); } Now, all blog pages work, including main blog page, archives, categories, and … Read more

Remove 2 categorgies when post status changes from private to publish

It is because you are trying to pass array of string instead of int. So it search for terms slug with this value instead in terms id. function remove2categories( $new_status, $old_status, $post ) { if ( $old_status == ‘private’ && $new_status == ‘publish’ && !in_category(array(3152), $post ) ) { $catsID = array(1186, 1208); wp_remove_object_terms( $post->ID, … Read more

products nested by subcategories in a current category archive

<?php $parentid = get_queried_object_id(); $args = array( ‘parent’ => $parentid ); $categories = get_terms( ‘product_cat’, $args ); if ( $categories ) : foreach ( $categories as $category ) : echo esc_html($category->name); $products = new WP_Query( array( ‘post_type’ => ‘product’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => $category->slug, ), ) ) … Read more