Comma separated tax terms, with “and” before last item [duplicate]

This is how your code should look like I added some comments so you will understand its simple programming not really wordpress related. $locations = get_the_terms($post->ID, ‘location’); $locations = array_values($locations); $total_locations = count($locations); // the total start from 1 for($i = 0; $i < $total_locations; $i++) { echo $locations[$i]; // echo the location if($i < … Read more

Search Query for Multiple Terms In Same Taxonomy

You need to make only one change in the form, change the first line to: <select name=”property_type[]” class=”form-control” multiple> Name of the field has to include [] to be considered as an array when it arrives on the server side. In the query string it will be listed as: property_type[]=condo&property_type[]=duplex And, on server side, when … Read more

Conditional Statement with Multiple Terms?

Firstly, create some sort of association between the icon class and the term name: $icons = array( ‘webinar’ => ‘fa-desktop’, ‘report’ => ‘fa-file-text-o’, ‘video’ => ‘fa-youtube-play’, ‘past-project’ => ‘fa-cogs’, ‘meeting-material’ => ‘fa-users’, ‘info-sheet’ => ‘fa-info-circle’, ); Then loop through each term assigned to the post and output the corresponding icon: $terms = get_the_terms( get_the_ID(), ‘type’ … Read more

Count Number of Posts in Taxonomy Term in Last 24 Hours

You can create a custom WP_Query and count its result. $wp_query = new WP_Query([ ‘tax_query’ => [ [ ‘taxonomy’ => ‘news’, ‘terms’ => $term_name, ‘fields’ => ‘name’ ] ], ‘date_query’ => [ [ ‘after’ => ’24 hours ago’ ] ] ]); $number_of_posts = $wp_query->found_posts; Edit I removed posts_per_page argument, as @birgire suggests, that found_posts offers … Read more

What does wp_term_taxonomy.parent reference?

WordPress doesn’t use actual FOREIGN KEY constraints in MySQL. So, technically, wp_term_taxonomy.parent is merely an integer. However, what you’ve found is correct: it refers to a term in wp_terms by its term_id. But, as you’ve also noticed, the term_id and term_taxonomy_id should always be the same. The reason they both exists is historical. Prior to … Read more

How do I return all terms from multiple taxonomies?

You have all sorts of fun questions today! There is also a WP_Term_Query available in WordPress. Here is some info on it as well as what parameters you can pass it. https://developer.wordpress.org/reference/classes/WP_Term_Query/__construct/ $term_args = array( ‘taxonomy’ => array(‘tax_one’, ‘tax_two’, ‘tax_six’), ‘hide_empty’ => false, ‘fields’ => ‘all’, ‘count’ => true, ); $term_query = new WP_Term_Query($term_args); foreach … Read more

get_terms() duplicate first term of a custom taxonomy

I think you want to show list of the category links right? but you are echo list inside the for-each loop. you have to write that outside of the loop. foreach ($terms as $term) { $term_list .= ‘<a class=”related-market btn btn-outline-secondary” href=”‘ . esc_url(get_term_link($term)) . ‘”>’ . $term->name . ‘</a>’; } echo $term_list; Also don’t … Read more

Why does wp_get_object_terms add a period after terms are output?

wp_get_object_terms() isn’t the problem. the_taxonomies() is doing the outputting; it doesn’t return anything. So, your code is equivalent to: the_taxonomies( ‘before=<ul><li>&sep=</li><li>&after=</li></ul>’ ); wp_get_object_terms( $id, null ); Now, if you go to wp-includes/taxonomy.php you will find the dot in the_taxonomies() source. To remove the dot, you need to add a filter: function remove_the_dot($template) { return ‘%s: … Read more

Taxonomy order exception for specific term

Here is the example of get_terms in the Codex: $terms = get_terms(“my_taxonomy”); $count = count($terms); if ( $count > 0 ){ echo “<ul>”; foreach ( $terms as $term ) { echo “<li>” . $term->name . “</li>”; } echo “</ul>”; } Lets say there was an ‘other’ term in my_taxonomy. To place it at the end … Read more