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

How to limit posts to 1 from each term with tax_query?

<?php $categories = array(‘economy’,’the-constitution’,’monetary-policy’,’liberty’); foreach($categories as $category) { $args = array( ‘posts_per_page’ => 1, ‘category_name’ => $category, ‘tax_query’ => array( array( ‘taxonomy’ => ‘highlight’, ‘field’ => ‘slug’, ‘terms’ => array( ‘lead’,’featured’ ), ‘operator’ => ‘NOT IN’ ) ) ); $wpse42358_query = new WP_Query( $args ); while( $wpse42358_query->have_posts() ) : $wpse42358_query->the_post(); // write post stuff here … Read more

Custom Query Arguments

/** * Define a new function that uses $args and wp_parse_args() */ function explain_parse_args( $args ) { $defaults = array ( ‘text’ => ‘wp_parse_args() merges $args into $defaults’, ‘before’ => “”, ‘after’ => ” \n”, ‘echo’ => TRUE ); // Parse incomming $args into an array and merge it with $defaults $args = wp_parse_args( $args, … Read more

How to update WordPress custom SQL Select query for custom taxonomies so that syntax is correct?

You should not use a direct SQL query, instead try the WP_Query tax queries e.g.: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => array( 22 ) ), array( ‘taxonomy’ => ‘job’, ‘field’ => ‘name’, ‘terms’ => $terms, ‘operator’ => ‘IN’ ) ) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)