How to add terms to my tax_query based off of the current post
‘terms’ => array(‘$tags1’), Remove the single quotes and it should look like ‘terms’ => array($tags1) OR ‘terms’ => $tags1 No need to make it an array, if you are using just one value.
‘terms’ => array(‘$tags1’), Remove the single quotes and it should look like ‘terms’ => array($tags1) OR ‘terms’ => $tags1 No need to make it an array, if you are using just one value.
Found problem. I replaced: $posts = $query->get_posts(); with: $posts = array(); if ($query->have_posts()){ while ($query->have_posts()){ $query->next_post(); array_push($posts, $query->post); } } And everything is working now.
If $taxonomy_category is already an array, then: ‘terms’ => array($taxonomy_category) should just be: ‘terms’ => $taxonomy_category where $taxonomy_category is equal to whatever was submitted from your form as $_POST[‘taxonomy_category’] or $_GET[‘taxonomy_category’]
Update 1 As @Florian pointed out, we do not need to use the wp_list_pluck function, we could simply add the ‘fields’ => ‘ids’ to the WP_Query to retrieve the list of ids: $producers = new WP_Query( array( ‘fields’ => ‘ids’, ‘post_type’ => ‘producers’, ‘posts_per_page’ => -1, ‘tax_query’ => array( array( ‘taxonomy’ => ‘region’, ‘field’ => … Read more
Thinking aloud here… $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘term_id’, ‘terms’ => array( 202, 203 ), ‘include_children’ => 1, ), array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘term_id’, ‘terms’ => array( 100 ), ‘include_children’ => false, ) ), ), ); … Read more
I did get the thing working, though I’m not entirely sure how. I made two changes: Removed the “convert array to Tax_Query object” step (which I only put in because using an array wasn’t working before) Added a direct assignment of the array to the $query object (rather than just using the set() method). My … Read more
So far good, add taxonomy condition by checking the suburbs and states Value. // Suburbs if( !empty( $_GET[‘suburbs’] ) ) { $suburbs = $_GET[‘suburbs’]; } // States if( !empty( $_GET[‘states’] ) ) { $states = $_GET[‘states’]; } // Query arguments. $args = array( ‘post_type’ => ‘properties’, ‘posts_per_page’ => 10, ); $taxquery = array(); // if … Read more
The problem is explained in the quote you’ve mentioned: “Default value is ‘publish’, but if the user is logged in, ‘private’ is added. And if the query is run in an admin context, protected statuses are added too. By default protected statuses are ‘future’, ‘draft’ and ‘pending’.” Ajax call is always considered to be from … Read more
Simply omit (or not add) tax_query part of arguments. $args = array( ‘post_type’ => ‘wr_event’, ‘posts_per_page’ => -1, ‘meta_key’ => ‘event_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => $order, ‘meta_value’ => $yesterday, ‘meta_compare’ => $compare, ); if ( ! is_null($cat) ) $args[‘tax_query’] =array( array( ‘taxonomy’ => ‘event_type’, ‘field’ => ‘slug’, ‘terms’ => $cat, ‘operator’ => ‘IN’ ), … Read more
You can do this with just get_terms – this allows you to fetch all (or some) of the terms from one (or more) taxonomies. By default it excludes ’empty’ terms, so you’ll need to set the arguments appropriately. //Array of taxonomies to get terms for $taxonomies = array(‘category’,’post_tags’,’my-tax’); //Set arguments – don’t ‘hide’ empty terms. … Read more