wp_set_object_terms() not adding new term to custom post and custom taxonomy

Use the fourth parameter in wp_set_object_terms() and pass true. wp_set_object_terms( $pid, $name, ‘name’, true); wp_set_object_terms( $pid, $email, ’email’, true); wp_set_object_terms( $pid, $birthdate, ‘dob’, true); Though I do find it weird to use taxonomies for name, email and birthdate. I’d recommend to use metadata for this. See: https://codex.wordpress.org/Function_Reference/update_post_meta Taxonomies are meant for categories and tags like … Read more

WordPress Genesis custom taxonomy archive shows 3 repeats of each post

You are using a nested loop in your code. You should only use the foreach loop, and pass the post ID to get_field(). Here’s an example: $terms = get_terms( [ ‘taxonomy’ => ‘collection_categories’, ‘orderby’ => ‘name’, ‘order’ => ‘DESC’ ] ); // Rest of the code here foreach ( $posts as $post ) { //* … Read more

List taxonomies according to whether this post is in another taxonomy in taxonomy archive

Well I got there, my public brain functions for all to see, hopefully someone somewhen will pass this was and find it useful. The code; // First get the type $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) ); $type = $term->slug; // we need to do some comparisons, here’s the variable $this_instance … Read more

get_posts of Custom Post Type AND Custom Taxonomy

You use multiple taxonomies at once, so use’relation’ => ‘AND’: <?php $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘products’, ‘post_status’ => ‘publish’, ‘tax_query’ => array( ‘relation’ => ‘AND’, // this is what was missing array( ‘taxonomy’ => ‘subjects’, ‘field’ => ‘name’, ‘terms’ => $shortcode_atts[‘subject’], ), array( ‘taxonomy’ => ‘plans’, ‘field’ => ‘name’, ‘terms’ => … Read more

shortcode to show custom post types by category

Here is a part in your code that may cause error: $catlist .= ‘<h2>’.the_title().'</h2>’; Try replacing with $catlist .= ‘<h2>’.get_the_title().'</h2>’; Explanation: the_title() echo the title of the post. But in your case you are using it within a function that will return the value. So you have to use get_the_title() instead. Thanks. Note: also there … Read more

Term count by user

It’s a little bit hard to guess, what are you trying to do exactly, but let me try to answer… My best guess is that you want to tell, how many properties has given user published in given property type. So first – why your code doesn’t work… get_term will get the term info and … Read more

How to query custom post types posts filtered by multiple custom taxonomies through a form selection

Apparently the problem was in the “AND” relation. Code now seems to work: <?php if(isset($_REQUEST[‘submit’])) { $prodotto = $_POST[“prodotto”]; $livello = $_POST[“livello”]; $ruolo = $_POST[“ruolo”]; $stato = $_POST[“stato”]; $args = array( ‘post_type’ => ‘corsi’, ‘posts_per_page’ => -1, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘prodotto’, ‘field’ => ‘slug’, ‘terms’ => … Read more

Custom Field Order by Last Name and First Name

Your code has a few issues, some unrelated, but generally, you need named meta queries to order by multiple meta keys: $posts = get_posts( [ ‘post_type’ => ‘soldier’, ‘posts_per_page’ => 5, ‘paged’ => $soldier_paged, ‘meta_query’ => [ ‘last_name_clause’ => [ ‘key’ => ‘last_name’, ‘compare’ => ‘EXISTS’ ], ‘first_name_clause’ => [ ‘key’ => ‘first_name’, ‘compare’ => … Read more