Running a custom query inside another cpt single and trying to grab a variable

Does this work? global $post; // make sure the post object is available $slug = $post->post_name; // get the slug // insert the slug into your query $args = array( ‘post_type’ => ‘client_prop’, ‘posts_per_page’ => 10, ‘tax_query’ => array( array( ‘taxonomy’ => ‘prop_neighborhood’, ‘field’ => ‘slug’, ‘terms’ => $slug, ) ) );

Function using get_posts() with tax_query not working when called from functions.php

For testing purposes in your functions.php file, try this – add_action(‘init’, ‘my_test_get_all_bands’, 99); function my_test_get_all_bands(){ echo ‘<pre>’; print_r(get_all_bands()); echo ‘<pre>’; } As I was attempting to say in my comment to your question (and as Pieter Goosen explained rather better), if your taxonomies have not yet been registered then the tax_query portion of your get_all_bands() … Read more

tax query shortcode

You just want to make sure you get all your default attributes set in addition to only adding tax queries when you have all the values set. <?php // [loop post_type=”website” taxonomy=”industry” terms=”beauty” posts=”3″][/loop] // [loop post_type=”website” posts=”-1″ ][/loop] function loop_recent_posts_shortcode( $atts ) { $a = shortcode_atts( array ( ‘posts’ => 6, ‘post_type’ => ”, … Read more

Custom tax_query filter not working for Woocommerce product categories

I figured out what the issue was. The page was displaying categories/subcategories and not the items themselves. This meant that woocommerce_product_subcategories() was the one filtering and that uses a different hook. Here is what I added to my functions.php file. add_filter( ‘get_terms’, ‘get_subcategory_terms’, 10, 3 ); function get_subcategory_terms( $terms, $taxonomies, $args ) { $new_terms = … Read more

tax_query (if the terms are empty)

I would start by reorganizing your $args code to make more sense. $now = date(‘d-m-Y H:i:s’); $cat=”featured”; $args = $cat_args = array( ‘post_type’ => ‘events’, ‘posts_per_page’ => 4, ‘meta_key’ => ‘start_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘ASC’, ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘start_date’, ‘value’ => date(‘Ymd’, strtotime(‘now’)), ‘type’ => ‘numeric’, ‘compare’ … Read more

How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?

Looking at WP_Tax_Query and WP_Meta_Query used by Wp_Query, they return their respective where clauses with an AND relation, and no hook or $args to change that behavior. Furthermore, the tax_query is computed before the rest of the main query so that it’s included in the main query in term_taxonomy_id IN (…) form. Also the WP_Tax_Query … Read more