Retrieve products with specific attribute and in category – woocommerce

You should use wc_get_products and a custom filter for adding your specific query. Example I want to find products containing a specific attribute value “table-filter”. $args = array( ‘table-filter’ => array(1,2,3) ); $products = wc_get_products($args); Than I have a filter for this: add_filter(‘woocommerce_product_data_store_cpt_get_products_query’, ‘my_handle_custom_query_var’, 10, 2); function my_handle_custom_query_var($query, $query_vars) { if (!empty($query_vars[‘table-filter’])) { $query[‘tax_query’][] = … Read more

Best Practice For Querying Grandchildren?

You’re on the right track. You can do this with just one MySQL query instead of two by joining on the post_parent. Drop this function into your functions.php file, then in your template you can replace your WP_Query call with $results = wpse_84810_get_grandchildren();, change your if clause to be if( $results && $results->have_posts() ), then … Read more

How do I search WordPress by different fields without a plugin?

I found a solution that allows me to search posts by tags and categories while still searching title and content. This does exactly what I was looking for. Credit: https://rfmeier.net/include-category-and-post-tag-names-in-the-wordpress-search/ add_filter( ‘posts_join’, ‘search_join’, 10, 2 ); /** * Joins the terms, term_relationship, and term_taxonomy tables. * * @global $wpdb * * @param string $join The … Read more

Search Custom Post with meta_value NULL

I depends if you’re looking for an empty value: $args = array( ‘post_type’ => LANDING__CUSTOM_POST, ‘meta_query’ => array( array( ‘key’ => ‘landing_exported’, ‘value’ => ”, ‘compare’ => ‘=’ ) ) ); // query $the_query = new WP_Query( $args ); which searches for value like: meta_value=”” or if you are looking for actually a NULL value … Read more