Restricted category in Woocommerce [closed]

The function that solves it should do the following : Loops through each product in the category For each item, retrieve the list of categories the product is in. If there is only one category and it’s the ‘restricted’ category, then the product is excluded from the query. Here’s an example : function exclude_category_archive_products( $q … Read more

How to sort posts alphabetically based on a specific parent category

You can use the following code snippet to sort posts alphabetically based on a specific parent category in WordPress: <?php $parent_cat=”Parent Category Name”; $parent_cat_id = get_cat_ID($parent_cat); $args = array( ‘category__in’ => array($parent_cat_id), ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘posts_per_page’ => -1 ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( … Read more

Using WP Query, I want to include all posts in category 1 as long as they are not also in category 2

I think, you can try this type of code. $args = array( ‘post_type’ => ‘product’, ‘meta_key’ => ‘sorting_weight’, ‘orderby’ => ‘meta_value_num’, ‘posts_per_page’ => – 1, ‘order’ => ‘DESC’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘term_id’, ‘terms’ => 81, // category 1 ), array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘term_id’, … Read more