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

wp_get_post_terms Order by not working

Your title is wp_get_post_terms Order by not working but if you use a custom post type you need to use wp_get_object_terms() I’m not sure what your aim is, but here is a code example you can try: $my_post_type=”post”; // edit this $my_taxonomy=”category”; // edit this $my_query = new WP_Query(array(‘post_type’ => $my_post_type,’posts_per_page’=>10)); if ($my_query->have_posts()) : while … Read more

Display all posts that use a custom taxonomy

I think your problem is here: ‘terms’ => array($clients_terms->slug) You define $clients_terms like so: $clients_terms = get_terms(‘clients’); …which will return an array of objects. But you try to access it as an object in your query args. That should be producing some kind of PHP notice? (Trying to get property of non-object, or something?) Try … Read more

Query to get term id using post id?

It is not good practice to use query when you have already builtin functions but for your need. Try this solution: global $wpdb; $meta = $wpdb->get_row( “SELECT * FROM `wp_postmeta` WHERE `meta_id` = $id” ); //will return same object like returned by get_metadata_by_mid() function print_r($meta); Debugging Technique: As you mentioned, get_metadata_by_mid() isn’t working on live … Read more