How to query term_id of a Custom Taxonomy by name

You can use the get_term_by function. This allows you to obtain a term (from a given taxonomy) by its slug or name (or id). The returned term object contains the term’s ID. For example: $term =get_term_by( ‘name’, ‘December-12’, ‘Birthday’); $term_id = $term->term_id; If ‘December-12’ is the slug, rather than the name, of the term, simply … Read more

Want Page Descendants when using query_posts post_parent or child_of

If you don’t have to use query_posts() then this is one method: function my_menu() { global $post; if(!$post->post_parent){ // will display the subpages of this top level page $children = wp_list_pages( array( ‘title_li’ => ”, ‘child_of’ => $post->ID, ‘echo’ => 0 ) ); } elseif($post->ancestors){ // diplays only the subpages of parent level $ancestors = … Read more

Can you have seperate sidebars for multiple taxonomy archives?

I’ve had luck dynamically creating sidebars using a foreach loop. You’d do something like this (untested) in your functions.php file: $my_terms = get_terms( ‘my_taxonomy_name’ ); if( ! is_wp_error( $my_terms ) ) { foreach( $my_terms as $term ) { register_sidebar( ‘name’ => $term->name . ‘ Archive Sidebar’, ‘id’ => ‘archive_sidebar_’ . $term->term_id ); } } Then, … Read more

Remove Parents From Permalink of Hierarchical Taxonomy

Simply set to false ‘hierarchical’=>true from rewrite parameter in your register_taxonomy. It should looks like this: register_taxonomy(‘places’, ‘post’, array( // Hierarchical taxonomy ‘hierarchical’ => true, ‘labels’ => array( //here your labels ), // Control the slugs used for this taxonomy ‘rewrite’ => array( ‘slug’ => ‘places’, ‘with_front’ => false, // Don’t display the category base … Read more

Avoid WP_Query’s duplicate posts with taxonomies

Pass the post ID from the first query as a post__not_in parameter to exclude it from the second query. $nature_loop_1 = new WP_Query( array ( ‘category_name’ => ‘nature’, ‘tax_query’ => array ( array ( ‘taxonomy’ => ‘highlight’, ‘field’ => ‘slug’, ‘terms’ => ‘sidebar-highlight’, ‘operator’ => ‘IN’ ) ), ) ); $exclude = $nature_loop_1->post->ID; $nature_loop_2 = … Read more

Trying to display terms from custom taxonomy within function

Function get_term_by returns object or array (based on $output arg) on success and false if failed. But you treat it as string and try to concatenate it. So your code should be following: $cat = get_term_by(‘id’, 17, ‘project_cats’); $html_content .= “<h3>” . rgpost(‘input_1’) . “</h3>”; //Title $html_content .= “<p><strong>Category:</strong> ” . rgpost(‘input_5’) . ” | … Read more