How to dynamically add custom taxonomy terms as a sub-menu of an existing menu item, using custom walker class

Okay, I figured it out. It’s not very smooth, but at least it works as I want it to. Will have to do some refactoring. The issue was that wp_nav_menu() got called earlier than the taxonomy registration. I had accidentally placed it in my theme-functions.php and forgotten about it, then called it again in my … Read more

how to create a proper query for getting a list of users with taxonomy related meta key

Objective I want to list sp_provider (hospital,clinics,doctors) whose sub_category is suppose ‘neurology’ rephrasing the words: I want to list users with sp provider category(meta value) such as “hospital” and the user have a sub category(meta value) “neurology” sp_provider is a meta value in user profile (sp-provider maybe a post-type or something for user management screen … Read more

How to get the first term for the current taxonomy?

You can use get_queried_object to get the term name. <?php if( is_tax() ) { global $wp_query; $term = $wp_query->get_queried_object(); $title= $term->name; } ?> To display: <?php echo $title; ?> If your on a taxonomy archive page you can use: <?php $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’ ) ); ?> Then to display … Read more

Sort a custom post type array numerically

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 … Read more

Limit tag cloud terms by date

Well it’s not that it’s not possible it just means it will take some effort. I am able to use an SQL query that combines the posts, term_relationships and terms tables. This allows a tag or name to be associated with a post which was published on a particular date. This was the sql statement … Read more

How to get a list of taxonomy terms which are being used only within certain post types?

I’m not a programmer so there’s probably a far more efficient/correct way of doing this. Put this in functions.php or a custom plugin: function get_terms_by_post_type( $taxonomies, $post_types ) { global $wpdb; $query = $wpdb->get_results( “SELECT t.*, COUNT(*) from $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN $wpdb->term_relationships AS r … Read more

get_terms on save_post hook

You’re on the right track. When you do something like this in a form.. <input name=”tax_input[formats][]” /> You create levels in the $_POST array. So you’d get the formats array like this… <?php $formats = $_POST[‘tax_input’][‘formats’]; Full example… <?php add_action(‘save_post’, ‘wpse74017_save’); function wpse74017_save($post_id) { // check nonces and capabilities here. // use a ternary statement … Read more

Custom query to get terms from post ids

It is not advised to make use of custom SQL queries if there are functions in WordPress that already does the job. To accomplish this, you can simply make use of wp_get_object_terms(). The first parameter $object_ids takes a string or an array of object ID’s. In your case, you can make use of an array … Read more