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

Why does WP_Query strip colons from tag names?

The tag parameter should be the tag’s slug. If you look at your tag’s archive URL (the view link when editing the tag), it won’t have the colon in it, because that’s not a legal character in a URL. Your tag’s name can still have the colon, and you can use the URLencoded version of … Read more

Retrieve Taxonomy Label

try this: private function get_taxonomy_by_term_id( $term_id ) { // We can’t get a term if we don’t have a term ID. if ( 0 === $term_id || null === $term_id ) { return; } // Grab the term using the ID then read the name from the associated taxonomy. $taxName=””; $term = get_term( $term_id ); … 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

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

Display a tag only if there is a description

The object returned by get_tags() should have a description property, so you don’t need to try to get it again. Just check to be sure $tags->description isn’t empty. You should probably also reorganize so that you don’t do anything at all unless if($tags). Thus: // Get ALL the tags! $tags = get_tags( array( ‘hide_empty’ => … Read more