Complex Taxonomy scheme

Set your system up like this: locations – CPT administrative – hierarchical taxonomy natural – hierarchical taxonomy type – non-hierarchical taxonomy In the administrative taxonomy, you would create your tree: countries on the first level, regions second, departments and so on. Then, you would assign your locations to the smallest administrative denominations among your taxonomies … Read more

Custom query for certain post type OR another post type with a certain category

First, take a look at this: https://developer.wordpress.org/reference/classes/wp_query/ You can filter by querying by post type, or in a single query (code between /* */). <?php //This is the first query $query_A = array( ‘post_type’ => ‘post_type_A’, ‘post_status’ => ‘publish’, //’cache_results’ => true, ‘posts_per_page’ => 10, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘fields’ => ‘ids’//add by … Read more

wp_get_object_terms count on taxonomies within an category archive

A simple function to count posts did the trick, but this is one more request in DB : function count_posts_in_cat_by_custom_term( $category_ID, $custom_taxonomy_name, $custom_term_id ){ $args = array( ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘category’ => $category_ID, ‘tax_query’ => [ [ ‘taxonomy’ => $custom_taxonomy_name, ‘fields’=>’term_id’, ‘terms’ => $custom_term_id, ] ] ); $posts = … Read more

WP_Query with tax_query not working

SQL query forming is wrong SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND 0 = 1 AND wp_posts.post_type=”product” AND (wp_posts.post_status=”publish”) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 1 Here 1=1 AND 0 = 1

Woocommerce – Shipping tax class based on cart items not using the highest tax available

I have found the answer by override the shipping tax filter // 0% and 21% tax producdts added combined to the cart needs to have 21% shipping tax add_filter(‘woocommerce_shipping_packages’, ‘override_woocommerce_shipping_packages’); function override_woocommerce_shipping_packages($packages) { $shipment_needs_tax = false; foreach ($packages[0][‘contents’] as $cartitem) { if (!empty($cartitem[‘data’]->tax_class)) $shipment_needs_tax = true; } if ($shipment_needs_tax && empty($packages[0][‘rates’][‘flat_rate:3’]->get_taxes())) { $shipcost = $packages[0][‘rates’][‘flat_rate:3’]->get_cost(); … Read more