Tag Info

Hot answers tagged

7

As you dive into WordPress, you'll find that WordPress has a lot of wrapper functions. For instance, there's add_theme_page that's just a wrapper of add_submenu_page. That's certainly not the only example (add_submenu_page itself has a bunch of wrappers, in fact). If you look at the source for get_categories(), you'll see that it too is a wrapper for ...


5

This should work for you: $taxonomyName = "age"; //This gets top layer terms only. This is done by setting parent to 0. $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'slug', 'hide_empty' => false)); echo '<ul>'; foreach ($parent_terms as $pterm) { //Get the Child terms $terms = ...


5

Thanks to Ivaylo for this code, which was based on Bainternet's answer. The first function (get_term_top_most_parent) accepts a term ID and taxonomy and returns the the term's top-level parent (or the term itself, if it's parentless); the second function (hey_top_parents) works in the loop, and, given a taxonomy, returns the top-level ancestors of a ...


5

I'm afraid this isn't possible natively (yet?). See this trac: http://core.trac.wordpress.org/ticket/18106 Similarly on the taxonomy admin page the post count reflects all post types. (I'm pretty sure there is a trac ticket for that too) http://core.trac.wordpress.org/ticket/14084 See also, this related post. New solution Having written the one below, ...


4

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 ...


4

here is a simple function that will get you the top most parent term of any given term: function get_term_top_most_parent($term_id, $taxonomy{ $parent = get_term_by( 'id', $term_id, $taxonomy); while ($parent->parent != 0){ $parent = get_term_by( 'id', $parent->parent, $taxonomy); } return $parent; } so once you have this ...


3

wp_terms_checklist early trigger a filter 'wp_terms_checklist_args' so you can use that filter to add your filter and auto-remove it haver 1st run. This should be enough, however, once hooks are global variables, to be sure is better use some stronger check, a static variable inside a function is a simple and nice trick: function switch_terms_filter( $_set ...


3

get_terms just returns an array of terms, it doesn't generate output. You have to do something with that array to see the results- $categories = get_terms( "category" ); echo "<ul>"; foreach ( $categories as $category ) { echo "<li>" . $category->name . "</li>"; } echo "</ul>"; See the other examples on the Codex page.


3

Public API for the rescue category is a Taxonomy that's already built in. Therefore it's quite easy to get its term count with get_terms( $tax, array( /* args */ ) ); $terms = get_terms( 'category', array( 'fields' => 'count', ) ); This will do a pretty fast COUNT (*) query so you don't have to worry about performance. Alternate solution You ...


3

If you'd like to list the individual courses, i.e. the taxonomy terms, you'd use neither WP_Query nor the WP standard Loop. Instead, make use of the get_terms function to retrieve the courses. It returns an array of term objects (if the taxonomy does exist and has terms matching the function arguments). Iterate over that and do something with it, such as ...


3

Not directly, because terms are assigned to posts, not authors. You will need to query all posts, get their terms and authors, and then filter out terms which came with posts that have other authors than get_query_var('author'). Note that depending on the number of posts your site has, this kind of query could be very expensive. A better way would be to ...


3

I'm not sure if I understand exactly what your trying to accomplish but I've outlined a way for you to sort the order of terms associated with the current post. Html for the term order metabox: echo '<ul id="the-terms">' $terms = get_the_terms( $post->ID, $taxonomy ); foreach ( $terms as $term ) { echo '<li ...


2

You could do something like this <?php $terms = get_the_terms( $post->ID, 'taxonomy_name' ); ?> <div class="myclass<?php foreach( $terms as $term ) echo ' ' . $term->slug; ?>"> <!-- content --> </div> http://codex.wordpress.org/Function_Reference/get_the_terms


2

get_terms function will return an array of object. Each of them has term_id field which contains id of a term. Just use it instead of slug and you will have what you need: <?php $terms = get_terms("ratios"); if ( $count($terms) > 0 ){ foreach ( $terms as $term ) { echo "<option value='" . $term->term_id . "'>" . $term->name . ...


2

Yes, but you need you make your own SQL query. A modified version of WP's get_term(): function &get_term_by_id_only($term, $output = OBJECT, $filter = 'raw') { global $wpdb; $null = null; if ( empty($term) ) { $error = new WP_Error('invalid_term', __('Empty Term')); return $error; } if ( is_object($term) && ...


2

I accepted One Trick Pony's answer because it got me on the right track and it does answer my question. However, in the end I am using this, it returns full term object with it's taxonomy fields. Though it's a bit hacky... /** * Get ther without khowing it's taxonomy. Not very nice, though. * * @uses type $wpdb * @uses get_term() * @param int|object ...


2

The only alternative I know of (using core functions) is: // Get terms whose name begins with "my_name" get_terms( 'category', array( 'name__like' => 'my_name' ) ); // Get terms whose name contains "my_name" get_terms( 'category', array( 'search' => 'my_name' ) ); If you need an exact match, you'll have to execute a custom query. ...


2

You can try getting all the posts IDs from the first taxonomy $objects = get_posts( array( 'category' => 'history', 'numberposts' => -1, ) ); foreach ($objects as $object) { $objects_ids[] = $object->ID; } Then get the terms from the second taxonomy associated with them: $collections = wp_get_object_terms( $object_ids, 'collections' );


2

Here's more of a complete guide based on the $wp_query object: The Taxonomy First you might want to know in which taxonomy you are, what its name is and retrieve all its available data from the object. // Taxonomy name $taxonomy = get_query_var( 'taxonomy' ); // Taxonomy object get_taxonomy( $taxonomy ); // Taxonomy name get_taxonomy( $taxonomy ...


2

Give: $terms = get_terms("my_taxonomy"); $count = count($terms); if ( $count > 0 ){ echo "<ul>"; foreach ( $terms as $term ) { if ($term->count > 2) { echo "<li>" . $term->name . "</li>"; } } echo "</ul>"; } a shot. It will grab all the terms and then run a check to see if the ...


2

This does basically the same as @Zach already added, but in a more smart/unreadable way :) $taxons = get_terms( 'some_taxonomy' ,array( 'hide_empty' => true // is the default ) ); $count = count( $taxons ); $stack = array() if ( 0 < $count) { // Catch all terms that have a count of "1" // As we already have excluded all ...


2

tax_query takes an array of tax query arguments arrays (it takes an array of arrays) but you are using only single array. The correct code is as following. $uposts = get_posts(array( 'post_type' => 'product', 'numberposts' => -1, 'tax_query' => array(array( 'taxonomy' => $cat->taxonomy, 'field' => 'slug', 'terms' => ...


2

<?php $terms = get_terms( $taxonomies, $args ); $term_name_array = array(); foreach($terms as $term){ $term_name_explode = explode("-",$term->term_name); $myterm_name=''; for($i=0;$i<count($term_name_explode)-2;$i++){ $myterm_name.=" ".$term_name_explode[$i]; } ...


2

I misunderstood what you were trying to do before. I thought you wanted to list the terms associated with one particular post - the one you are on. Whoops! Try this instead: $terms = get_terms('fruit_category'); if(!empty($terms)){ echo "<ul>"; foreach ( $terms as $term ) { echo '<li><a ...


2

Here's the correct syntax for what you're trying to do, if there's just the single value for the 'series' custom taxonomy slug that you're trying to retrieve. You were passing the whole array to your echoed string. I made a new variable $series which pulls the first/only value in the $terms_slugs array. And simplified a few other things you didn't need in ...


2

In wordpress a parent for a term is always referred to the same taxonomy. So as you already understand what you need is create a texonomy in which parent term rapresents a 'School' and a child term rapresents a 'Group.' Maybe a third-level-term rapresents a 'Sub-Group' or something else. Doing so and using the argument parent and/or child_of in get_terms ...


2

That field can return multiple term objects depending on how you've got it configured, so I'll guess that $series in this case is an array containing a single element, which contains your term object. Try inspecting the contents of series: print_r( $series ); You'll probably see something like: Array ( [0] => stdClass Object ( ...


2

You will need to filter the query, which you can do with the terms_clauses hook. This is very similar to G-M's solution but does not require a prefix on your search string. function old_style_name_like_wpse_123298($clauses) { remove_filter('term_clauses','old_style_name_like_wpse_123298'); $pattern = '|(name LIKE )\'%(.+%)\'|'; $clauses['where'] = ...


2

This is more of a PHP question, but the solution is simple - you need to use a foreach-loop on $getslug, because you just echo the slug of the first taxonomy. The function wp_get_post_terms() does not return a single object, but an array of objects. You are right with the [0], this indicates that you are checking the first entry of said array. Your ...


1

The WordPres Core function wp_list_pluck() should make this fairly easy. $getslugid = wp_get_post_terms( $post->ID, 'opd_taggallery' ); $slugs = implode(', ',wp_list_pluck($getslugid,'slug')); echo $slugs;



Only top voted, non community-wiki answers of a minimum length are eligible