Parse error: syntax error, unexpected ''tax_query'' in wordpress

hi i want to display posts by term. first the code display all the posts: $aProjectArgs = array( 'post_type' => 'uni_project', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'asc' ); so i add another part of code to display posts by term: $aProjectArgs = array( 'post_type' => 'uni_project', 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'asc' 'tax_query' => array( array( 'taxonomy' => 'post_tag', 'field' => 'id', 'terms' => 43 ) ) ); but its not working its give …
Category: Web

Order WP_Query by The Order of an Array in Tax_Query

I have a wp_query that uses tax_query to which I pass an array of taxonomy term IDs. I'd like to order my results based on the order of that array but can't get it to work and searching has got me nowhere. Example code below for reference. So this code actually orders the results by tax terms (dumb luck?) but the tax terms aren't in the same order as $term_array. I've tried all the logical options for the 'orderby' parameter …
Category: Web

Hiding taxonomies with no children WP_Query & tax_query

I have this code which has taken over 7 hours to put together through research but the last hours or so I have hit a brick wall! I require the taxonomy title to be hidden if there are no posts associated with it. Here is the page: http://cb.dannycheeseman.me/wine-menu/usa/california/ Here is my code: /**********************************************/ // CUSTOM WINE MENU SHORTCODE /**********************************************/ add_shortcode( 'wine_list_per_cat', 'wine_list_per_cat' ); function wine_list_per_cat($atts){ global $woocommerce_loop; extract(shortcode_atts(array( 'cat' => '', // list of categories in the format 0,1,2,3,4 'tax' …
Category: Web

Sort by an ACF field in a tax_query

I do not find the solution which must surely be surely simple. (I'm new to WP) I have an ACF field named "partners_order". I would like to sort it in ascending order (ASC) here's what i tried <?php $terms = get_terms('type_partenaires'); usort($terms, function($a, $b) { return get_field('ordre_affichage', $a) - get_field('ordre_affichage', $b); }); foreach ( $terms as $term ): ?> <?php echo $term->name; ?> <?php $loop = new WP_Query( array( 'post_type' => 'partenaires', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => …
Category: Web

tax_query showing no results

I'm creating a music database site with two custom post types: tracks and albums. I've linked the tracks to their respective albums with a custom taxonomy for the album's slug. On each album page, I'm trying to get a tracklist of the album by retrieving all tracks with a dub_album_slug taxonomy that matches the slug of the current album. Here's my code for that query: global $post; $post_slug = $post->post_name; $args = array ( 'post_type' => 'dub_track', 'tax_query' => array( …
Category: Web

Any quicker alternative for WP_Query "NOT IN"

I am using the following wp_query to pull up a list of post, and I want to exclude a few categories of a custom taxonomy. It works well, however Query Monitor is telling me that the query is slow. I removed the 'tax_query' part of the query and it sped up. Is there a faster way to exclude these categories? Thanks! My Query: $args = array( 'post_type' => array( 'recipe' ), 'post_status' => array( 'publish' ), 'order' => 'DESC', 'orderby' …
Category: Web

Custom Widget WP_Query problem

I have everything working on my widget except the results! I created a taxonomy called country names that we use for several custom post types. I created this widget to display tour guides (CPT) from the selected country. The widget is working properly on the back end, but I am getting no results on the front end (ie. "No listing found"). I have echoed the $instance to the screen and it is correct, so my args or query must be …
Category: Web

?cat=-1 Indexed Versions Of Homepage

I'm finding some strange query strings on my homepage are indexed in Google and causing duplicate content. A couple of examples: https://sciencetrends.com/page/103/?cat=-1 https://sciencetrends.com/?cat=-3 I'm not sure how or why these pages are being created in Wordpress but it seems common for even large Wordpress sites: https://techcrunch.com/page/10/?cat=-1 https://blogs.wsj.com/law/page/10/?cat=-1 https://www.nytco.com/page/10/?cat=-1 http://www.bbcamerica.com/page/10/?cat=-1 Ideally, I'd like to remove all ?cat=* pages from the site and have then resolve to 404. Any thoughts on the best method to do so, .htaccess, Wordpress modification, etc.?
Category: Web

Not able to get my custom search result using meta_query and tax_query together?

I created a custom search where i am able to show the Fields (ACF fields) and also Taxonomies. But while I am searching by taking the combination of both Taxonomies and meta fields, i am not getting the results. It is giving the results if i will search either Taxonomies or meta fields. How to make both conditions work together? This is my code where i mentioned both meta_query and tax_query:- <?php if($_POST){ $_speciality = $_POST['speciality'] != '' ? $_POST['speciality'] …
Category: Web

WP_Query tax_query on ACF post_object

I have a custom post type Wine, which has an ACF Field that links to another custom post type Producer as a post_object relation. In my Producer, I have a custom taxonomy named Region. Now, what I'm trying to do is to query all the white wines where the producer's region is x. Here's what I've tried: $args = array( 'post_type' => 'wines', 'posts_per_page' => 12, 'tax_query' => array( array( 'taxonomy' => 'type', 'field' => 'slug', 'terms' => 'white' ), …
Category: Web

Tax Query on product_cat using NOT IN as operator does not exclude that category

Using the following code, I expect $items to not include products with the product category "stones." However, that is not the result. It doesn't seem to be excluding that category at all. Syntax looks right - are there other reasons why WordPress wouldn't respect this "NOT IN" statement? $tax_query = array( array( 'taxonomy' => 'product_cat', 'terms' => array('stones'), 'field' => 'slug', 'operator' => 'NOT IN', ), ); $args = array( 'post_type' => 'product', 'posts_per_page' => -1, 'tax_query' => $tax_query ); …
Category: Web

How to print term name inside wp post loop

I have 3 different taxonomies in a custom post type. I want to print all posts with term name with them. for example: taxonomy 1 =>taxonomy=banks&post_type=creditcards taxonomy 2 =>taxonomy=joiningfees&post_type=creditcards taxonomy 3 =>taxonomy=cardtype&post_type=creditcards So I want to print all the custom posts with the term names I am able to print data by entering single taxonomy but how to print data with all the taxonomy terms Query $custom_terms = get_terms('banks'); foreach($custom_terms as $custom_term) { wp_reset_query(); $args = array('post_type' => 'creditcards', 'tax_query' …
Category: Web

Override tax_query with pre_get_posts to include other term_ids on a single category

I'm trying to include more than one term_id(multiple checkboxes filter) on a single category page. I managed to recollect enough to build a tax_query with pre_get_posts, but now it seems, I have two tax_queries, one is in WP_Query->query_vars and the other is just in WP_Query(that one is of WP_Tax_Query type): object(WP_Query)#1968 (50) { ["query"]=> array(1) { ["product_cat"]=> string(77) "parent-category-slug/slug-of-the-category" } ["query_vars"]=> array(59) { ["product_cat"]=> string(56) "slug-of-the-category" ["error"]=> string(0) "" ["m"]=> string(0) "" ["p"]=> int(0) ["post_parent"]=> string(0) "" ["subpost"]=> string(0) "" …
Category: Web

Extending WP Query: Custom geolocation meta values work, but tax_query breaks

I've built a custom query for geolocation searches. I'm saving lat and lng within each custom post type as a meta value. My query extension returns results successfully when lat and lng are the only search variables. Problem: I would like to also add tax_queries to my query to further select posts Class to extend query: class WP_Query_Geo extends WP_Query { function __construct( $args = array() ) { if(!empty($args['lat'])) { $this->lat = $args['lat']; $this->lng = $args['lng']; $this->distance = $args['distance']; $this->lat_meta_name …
Category: Web

Using get_posts, I need to use a combination of OR & AND relations

Using WordPress v4.6, I set up arguments for get_posts() based on price (2 conditions), sku, and categories like this: [meta_query] => Array ( [relation] => AND [0] => Array ( [key] => _price [value] => Array ( [0] => 0 [1] => 5 ) [type] => DECIMAL [compare] => BETWEEN ) [1] => Array ( [key] => _price [value] => Array ( [0] => 50.01 [1] => 100 ) [type] => DECIMAL [compare] => BETWEEN ) [2] => Array ( …
Category: Web

WordPress Multiple Taxonomy Query

I've a simple form made up of two multiple selects which (as if by magic) filters my posts archive with URL parameters: <form class="filters"> <select name="country" multiple> <option value="united-kingdom">United Kingdom</option> <option value="ireland">Ireland</option> </select> <select name="type" multiple> <option value="director">Director</option> <option value="partner">Partner</option> </select> <input type="submit"> </form> If I select 'Ireland' and 'Partner' I'm sent to: https://example.com/network/?country=ireland&_type=partner Then, if I select multiple values such as 'Ireland', 'United Kingdom' and 'Partner' I'm sent to: https://example.com/network/?country=ireland&country=united-kingdom&_type=partner My question is, how can I use this form …
Category: Web

Get the tax term in which is a post via wp_query

I'll rewrite my original question because I feel like I can't be understood : I made a template page on which I have different WP_Query. I have a category taxonomy (countries). This template page matches with one of this tax's terms. For example, the page France matches with the category tax term $countries->france The administrator have the ability, if he wants, to create a translation which will be seen on the same page template. Those translated posts will be categorized …
Category: Web

List only parent attributes on woocommerce admin atrributes page

I would like to add option on attributes page screen options, to filter out only parent attributes. The main struggle is that I can't even alter the query... I tried actions: parse_query, pre_get_posts but it looks like these are not suitable for taxonomy query. public function prepare_items() - doesn't have any hook to add more arguments... Please point me to the right direction.
Category: Web

Get categories that has posts with a certain tag

I have a tag template where I list all the products based on category and tag combined. At the bottom of this page I want to show the visitor all the other categories that have products with the same tag (product brand in this case). I've tried with the code below but nothing gets returned. Am I thinking about it in the wrong way maybe? $terms = get_terms( array( 'taxonomy' => 'category', ) ); // Loop through them foreach($terms as …
Category: Web

Fastest way of counting posts of a custom post type in a specific taxonomy term?

I know this kind of question is legion but I have read through all related topics and I can't find a satisfying solution. What I want to achieve is simple: on my taxonomy (author) term archive page I have a list of all terms within that taxonomy from which you can select to switch from one term to another. I want to display the number of posts only from the post type (several CPT are associated with author). Simply put …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.