How to pass taxonomy terms to WP_Query along with $args?

I created a cpt and custom taxonomy associated with it. Lets say custom taxonomy name is Sports. I added terms to it - football, basketball. Now, i want to fetch post titles tagged under football and basketball separately on same page.(Note:- i am using a custom page template to show list of articles from CPT). $args = array( 'post_type' => 'sports', 'tax_query' => array( array( 'taxonomy' => 'sports_category', 'field' => 'slug', 'terms' => 'football' ), ), ); $myquery = new …
Category: Web

get_object_term_cache duplicate terms after update to wordpress 6

After WordPress update to 6 versions receives an issue. receive duplicated terms on function echo wp_kses_post(get_the_term_list($product->get_id(), 'product_cat', '', ', ', '')); and echo wp_kses_post( get_the_term_list( $product->get_id(), 'pa_material', '<li class="material">', ', ', '</li>' )) ? : ''; All work correctly before the update. I found that get_object_term_cache( $post->ID, $taxonomy ); give me duplicated terms What can cause this issue? Plugin or function change? (unable to find detail WP 6 changelog)
Category: Web

How to automatically create a terms based on each post of a post type

I am working on a music site which has custom post types- 'artists', and 'releases'. I have about 3,000 artists, and about 19,000 Releases in my database. It's been suggested to me that I should create a taxonomy term for each release and each artist to eliminate some slow queries on my site. Anyway, I know how to create a new taxonomy, and how to make terms by hand. How can I auto create terms in my release taxonomy, where …
Category: Web

get_the_terms() returning wrong results inside of loop

When I use get_the_terms() inside a loop, the whole thing behaves very strangely. Sometimes the terms are included twice or three times and sometimes a post inside of the loop returns only false. I have used get_the_terms() over and over for the last few years without any problems. So i'm quite confused right now. It seems like wp_get_post_terms() and wp_get_post_categories() are getting out the correct data but I would like to know why get_the_terms() is behaving this way inside of …
Category: Web

Count posts per taxonomy else change taxonomy if less than x number

$taxonomy = $tag->count > 3 ? 'post_tag' : 'category'; $cats_or_tags = $tag->count > 3 ? $tag_ids : $cat_ids; $args = array( 'tax_query' => array( array( 'taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $cats_or_tags The first part of this ternary works when checking the count of posts in a specific tag but the 2nd part doesn't. It's supposed to set the taxonomy and terms values if there's more than 3 posts tagged otherwise when less than 4, display posts from …
Category: Web

How to add custom meta to 'pre_get_terms'?

I have a custom taxonomy with custom meta. I have added the custom meta values to columns in the admin list page just fine. But if I search for values that are in these columns nothing is found. I'm assuming I need to use pre_get_terms, but am having trouble figuring out how to include the meta in the query. Here is what I am trying to do to test one of the fields, but results are still negative. add_action( 'pre_get_terms', …
Category: Web

Update wordpress post terms programatically

I am currently working with woocommerce for wordpress and making a custom plugin. I would like to update the product categories manually through my own admin panel, here is what I have so far: $catTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC')); This gets all product categories when looped. I then add checkboxs to the items in the loop like this: <label><input name="" type="checkbox" value="" id="cat_term_<?php echo $catTerm->name;?>" name="cat_term[]" /><?php echo $catTerm->name; ?></label> I then save the terms like …
Category: Web

Filter "get_terms" query

I'm currently getting the data from a custom taxonomy using this: $terms = get_terms(array( 'taxonomy' => 'my_custom_taxonomy_name', 'hide_empty' => true )); Now, this returns a lot of stuff in each WP_Term object; term_id, name, slug, term_group, term_taxonomy_id, taxonomy, description, parent, count and filter. I only need to get 2 of those: name and slug. How can I filter that query so it doesn't returns all that unused data?
Category: Web

how do you get one specific term from a shortcode attribute?

I'm working on a function where I just want to output a button that links to a specific term. I have used get_the_terms and have gotten it to work successfully, but I've been trying get_term and I've have no luck. I want the shortcode to look like this [see_all_products category="bakery"] and output a button that links to it. This is my function so far: function product_category_button($atts) { extract(shortcode_atts(array( 'category' => '', ), $atts)); // if( $category ) : // Vars …
Category: Web

using wp_insert_term to create custom terms for a custom taxonomy from frontend form,

I have a form which allows certain roles to add custom terms to a taxonomy. My taxonomy is called Genre (slug genre) <form method='post' enctype='multipart/form-data'> <input type="text" value="" name="new"> <input type='submit' name='Save'> </form> I have been going around in circles with this for hours. Ive searched for other questions similar and have tried the suggestions. I am using https://wordpress.org/plugins/custom-post-type-ui/ to create the custom taxonomies - Was wondering maybe my script is firing before this plugin does and therefore wp_insert_terms happens …
Category: Web

Displaying custom-taxonomy-terms sorted by parent/child-hierarchy?

I have a custom post type with a custom taxonomy (to show some "best practice" examples on my website). On the single-post-page (single-bestpractice.php) I wanted to show all the terms (categories) like this: Parent: Child, Child, Child I tried this code: $customPostTaxonomies = get_object_taxonomies('bestpractice'); if (count($customPostTaxonomies) > 0) { foreach ($customPostTaxonomies as $tax) { $args = array( 'orderby' => 'name', 'show_count' => 0, 'pad_counts' => 0, 'hierarchical' => 1, 'taxonomy' => $tax, 'title_li' => '' ); wp_list_categories( $args ); } …
Category: Web

For each loop on every word in post

I'm having a recipe site where every post naturally contains ingredients. Every ingredient is a tag, and I would like to automatically link every ingredient so the user can click on it and see all recipes that uses that certain ingredient. For this to be possible I guess I have to loop through every word in the post, then check if that word is equal to an existing tag, and wrap that word in a hyperlink. But I'm not sure …
Category: Web

Getting a taxonomy's thumbnail url

This is how I am currently trying: $taxonomies = array( 'product_cat' ); $args = array( 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(), 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'hierarchical' => true, 'child_of' => 0, 'childless' => false, 'get' => '', 'name__like' => '', 'description__like' => '', 'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' ); $terms = get_terms($taxonomies, $args); …
Category: Web

list taxonomy terms in current post / current category

i need to display taxonomy terms in a custom post and also in archive / category page of that post type. terms must be from current post or current category https://stackoverflow.com/questions/15502811/display-current-post-custom-taxonomy-in-wordpress code in this thread works for only single post, can i make it work in archive / category page too pls.
Category: Web

Displaying subcategories and then posts in taxonomy template

I have a custom post type 'downloads' which i have a have a custom template set up to get terms of to begin with. Im now trying to set up my taxonomy template so that it displays sub-categories if there are any, but if not to show posts for that term. Below is what my taxonomy template includes so far and this works fine to the point that it displays the child categories, but it doesnt then show the posts …
Category: Web

List post from current taxonomy children

I have a custom post type and a taxonomy with children, with a template file named taxonomy-productcategories.php. On this i want to list all children with their posts. Child taxonomy 1 Child taxonomy 1 Post A Child taxonomy 1 Post B Child taxonomy 1 Post C Child taxonomy 2 Child taxonomy 2 Post D Child taxonomy 2 Post E Child taxonomy 2 Post F And so on... I have an example for getting just the Child taxonomy, but i want …
Category: Web

Set term on an attachment using wp_set_object_terms and want to display the full term text but it's showing a slug instead

I have a form that visitors use to upload files and fill out information about them and a function that adds those files to the media library and set various fields (including some custom taxonomies) on the media library items based on fields that the visitor filled out in the form. The problem is, I have an email address field. When a visitor fills out the email address field with "[email protected]", what is displayed on the Attachment details screen (as …
Category: Web

How to use germ_terms() with meta_query for ACF Taxonomy field?

I have a custom taxonomy, Events (“event”). Through ACF, this also has a Taxonomy field, “Topic”, linking it to a secondary taxonomy, Topic (“topic”). I want to get_terms() for all Events terms which bear the specific “Topic” term “Media”, which happens to have term ID 422. I know get_terms() can take meta_query, but I don’t understand how to properly get what I need. Both of these return no results… 'meta_query' => array( array( 'key' => 'Topic', 'value' => '422', ) …
Category: Web

How to get several fields from wp_query?

I'm going to get several fields from wp_query result. I know about wp_list_pluck() function, but it accepts only one field paramether. How to get several ones if I'd like to take several parameters from each post found? [ Object1 (ID, name, tag), Object2 (ID, name, tag), Object3 (ID, name, tag), etc. ] Thank you for your help afterwards! My code excerpt is here: $search_param = get_param('search_param', null, 'text'); // POST param $term_id = get_term_by('name', "$search_param", 'image_color')->term_id; $args = array( 'post_type' …
Category: Web

About

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