How can I query for all values of a custom taxonomies?
Use get_terms($taxonomy, $args) $terms = get_terms(‘Fruits’); Codex page
Use get_terms($taxonomy, $args) $terms = get_terms(‘Fruits’); Codex page
If you are retrieving post(s) by ID, then why do you need terms in query? Post IDs are unique. You likely need post type (because it’s not default), but taxonomy terms only add confusion to the mix. Update Noticed after you added second code sample – post__in has two underscores in it, your examples lack … Read more
Before the loop starts use query_posts. Available parameters are here. Something like this: global $wp_query; query_posts( array( ‘post_type’ => ‘mycustomname’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘mytaxonomyname’, ‘field’ => ‘slug’, ‘terms’ => array( ‘myterm1slug’, ‘myterm2slug’ ) ) ) ) );
You should be able to do something like this: add_action(“manage_posts_custom_column”, “my_custom_columns”); add_filter(“manage_edit-[POSTTYPE]_columns”, “my_new_columns”); function my_new_columns($columns) { $columns = array( “image” => “Image” ); return $columns; } function my_custom_columns($column) { global $post; if (“ID” == $column) echo $post->ID; elseif (“image” == $column) echo ‘default_value’; } Then you should be able to use $tax_term->image to show it. … Read more
Just replace tax_name with the desired taxonomie $tax = wp_get_post_terms($post->ID, ‘tax_name’); echo $tax[0]->slug;
Looking at the source (edit-tag-form.php) it doesn’t look like there is a way of doing this through filters, as the code is directly outputted as oposed to being held in a variable. All {$taxonomy}_pre_edit_form does is allow you to add code before the form. JS I think is the only way, and to be honest … Read more
if ( ! isset($term_taxons->errors)) { ?> Show Child Taxons <?php } else { ?> SHOW PRODUCTS <?php } ?> get_term_children returns a WP_error on failure.
function trunc($phrase, $max_words, $after = null) { $phrase_array = explode(‘ ‘,$phrase); if(count($phrase_array) > $max_words && $max_words > 0) $phrase = implode(‘ ‘,array_slice($phrase_array, 0, $max_words)) . $after; return $phrase; } This function returns the input shortened if there are more words in it than $max_words. You use it like this: $string = “This is a sample … Read more
For what it’s worth, I just gave up on the ‘__not_in’ approach and went with the following somewhat sneaky solution: //Create the exclusion rule $new_tax_query = array( array( ‘taxonomy’ => ‘x_category’, ‘field’ => ‘slug’, ‘terms’ => array(‘y-slug’), ‘operator’ => ‘NOT IN’, ) ); //If there is already a tax_query, ‘AND’ our new rule with the … Read more
<?php $categories = array(‘economy’,’the-constitution’,’monetary-policy’,’liberty’); foreach($categories as $category) { $args = array( ‘posts_per_page’ => 1, ‘category_name’ => $category, ‘tax_query’ => array( array( ‘taxonomy’ => ‘highlight’, ‘field’ => ‘slug’, ‘terms’ => array( ‘lead’,’featured’ ), ‘operator’ => ‘NOT IN’ ) ) ); $wpse42358_query = new WP_Query( $args ); while( $wpse42358_query->have_posts() ) : $wpse42358_query->the_post(); // write post stuff here … Read more