orphaned taxonomy terms remove by sql query
You shouldn’t need to use a custom SQL query – stick to the built-in method wp_delete_post(). This will also clear out all term relationships too.
You shouldn’t need to use a custom SQL query – stick to the built-in method wp_delete_post(). This will also clear out all term relationships too.
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
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
You could simply check if a post exists. Otherwise, you can get the currently viewed term: // Check if we have posts to work with if( ! have_posts() ) { $term = get_queried_object(); // Get the current term } // Check if we have a term to work with if( ! empty( $term ) ) … Read more
It’s much simpler than you think. The function you will be dealing with is wp_insert_term as I am assuming you only want to provide basic functionality to add a new term (club) and not update terms I won’t cover the wp_update_term function now. The example below is very basic and is intended to be that … Read more
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
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
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.
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
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 );