Add a term to an attachment submitted from front end

media handle sideload returns an attachment ID, and attachments are normal posts with the post type ‘attachment’. All the same things apply, featured images parents taxonomies post meta etc albeit with a few attachment oriented functions like wp_get_attachment_image So use wp_set_object_terms as you normally would, e.g.: $id = media_handle_sideload(…. if(!is_wp_error($id)){ wp_set_object_terms( $id, array(terms…), $taxonomy, $append … Read more

Trying to list terms of a custom taxonomy using get_categories

get_categories() fetches taxonomies of type ‘categories’ particularly http://core.trac.wordpress.org/browser/tags/3.6/wp-includes/category.php#L0, to fetch custom taxonomy you should use get_terms() instead, here http://codex.wordpress.org/Function_Reference/get_terms $terms = get_terms( ‘partner-cat’, ‘orderby=count&hide_empty=0’ ); $count = count($terms); if ( $count > 0 ){ echo “<ul>”; foreach ( $terms as $term ) { echo “<li>” . $term->name . “</li>”; } echo “</ul>”; } Make sure … Read more

Custom Roll/Custom Post Type – Can’t Select Categories

I had the same problem, a custom role couldn’t assign categories to my CPT. When doing register_taxonomy(), I added these capabilities: ‘capabilities’ => array ( ‘manage_terms’ => ‘manage_options’, //by default only admin ‘edit_terms’ => ‘manage_options’, ‘delete_terms’ => ‘manage_options’, ‘assign_terms’ => ‘edit_cpt-type’ // can edit cpt-type i.e. custom role ), Hope this helps to people and … Read more

tax_query: What to pass when I want to have all terms?

Simply omit (or not add) tax_query part of arguments. $args = array( ‘post_type’ => ‘wr_event’, ‘posts_per_page’ => -1, ‘meta_key’ => ‘event_date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => $order, ‘meta_value’ => $yesterday, ‘meta_compare’ => $compare, ); if ( ! is_null($cat) ) $args[‘tax_query’] =array( array( ‘taxonomy’ => ‘event_type’, ‘field’ => ‘slug’, ‘terms’ => $cat, ‘operator’ => ‘IN’ ), … Read more

Get Term names from WP Term Object

Here’s an alternative using the handy wp_list_pluck(): $terms = get_terms(array( ‘taxonomy’ => ‘category’, ‘hide_empty’ => false, )); $slugs = wp_list_pluck( $terms, ‘slug’ ); $names = wp_list_pluck( $terms, ‘name’ ); where we pluck out the wanted field into an array.

Alphabetical order in taxonomy.php

The main query is generated before the template is loaded, the results of the main query are how WordPress knows what template to load. If you want to alter query parameters of the main query to change things like orderby, you should add a function hooked to pre_get_posts. The argument passed to the function contains … Read more

How can I remove links from the function “get term list”?

It may be easier to just write the list manually, something like: <?php $terms = wp_get_post_tags( $post->ID ); //For custom taxonomy use this line below //$terms = wp_get_object_terms( $post->ID, ‘people’ ); foreach( $terms as $term ) $term_names[] = $term->name; echo implode( ‘, ‘, $term_names );

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)