Custom Taxonomy Query

NOTE: This answer is supposed to be in addition to the answer here The function used returns an array of all the items, so the best way to display them is to use a foreach loop. As a usage example global $wpdb; $result = $wpdb->get_col(….); //copy the line from the aforementioned answer if($result) { echo … Read more

List related terms + taxonomies

You probaby want get_terms(). WordPress keeps a count of the number of posts that use a taxonomy and you can filter your query using it: // get all the terms in the ‘category’ taxonomy $terms = get_terms(‘knife’); // list all the terms that have at least one post foreach ($terms as $term) { echo “{$term->name} … Read more

How do I display a custom field from a custom taxonomy in single.php?

Catchable fatal error: Object of class stdClass could not be converted to string in /wp-content/themes/new/single.php on line 22 This is because $wpdb->get_row returns an object by default and you can’t echo an object. Changing echo $toc to echo $toc->meta_value will give you your desired result. Your other problem is that multiple terms can have have … Read more

Can’t set custom taxonomy terms via custom form

Have you tried wp_set_object_terms? …which needs to be placed after your call to wp_insert_post as it requires the post ID in order to attach the correct terms, to the right taxonomy with the right post. //add_action(‘plugins_loaded’, ‘newpost’); # will not work, user not authenticated add_action(‘init’, ‘newpost’); // will work, user authenticated function newpost() { if … Read more