How to get the top most term (top ancestor) of a custom taxonomy child term?
I guess this function is what you are looking for -> get_ancestors()
I guess this function is what you are looking for -> get_ancestors()
I don’t know which line that error refers to but this code works correctly if everything falls into place exactly right. But there are actually several ways this could go wrong. For example, if get_query_var(‘author_name’) is not set you get an error on this line: $used_terms=list_author_used_terms($user->ID); If a problem occurs here: $terms = wp_get_object_terms( $p->ID, … Read more
Filter pre_get_posts: add_filter( ‘pre_get_posts’, ‘wpse_98213_add_post_types_to_tax_query’ ); /** * Let WP search for custom post types on taxonomy archives. * * @wp-hook pre_get_posts * @param object $query * @return object */ function wpse_98213_add_post_types_to_tax_query( $query ) { if ( ! is_main_query() or ! is_tax( ‘your_taxonomy_name’ ) ) return $query; $query->set( ‘post_type’, array ( ‘portfolio’, ‘post’ ) ); … Read more
Your tax_query is incorrect. taxonomy does not take an array. taxonomy (string) – Taxonomy. http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters You will need to rewrite your arguments to be more like the following from the Codex: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘movie_genre’, ‘field’ => ‘slug’, ‘terms’ => array( ‘action’, ‘comedy’ … Read more
Just needs a little array manipulation. $def = array( ‘taxonomy’ => ‘cities’, ‘field’ => ‘slug’, ‘operator’ => ‘NOT IN’ ); $cities = array( ‘boston’, ‘chicago’ ); $args = array(‘relation’ => ‘OR’); foreach ($cities as $c) { $args[] = wp_parse_args(array(‘terms’=>$c),$def); } print_r($args); The $cities array you need to build from your $_POST or $_GET form data, … Read more
I know I am not answering exactly your question but in my opinion it is best to do it manually without messing with rewrite rules and filters. That way you keep also the default URL structure for terms templates, other plugins etc. $terms = get_the_terms( $post->ID, ‘industry’); if($terms && !is_wp_error($terms)){ echo ‘<ul>’; foreach ( $terms … Read more
Your permalink as given is domain.com/curriculum-area/equality but you registered your taxonomy as Curriculum Area. For domain.com/curriculum-area/equality to work, change Curriculum Area in: register_taxonomy( ‘Curriculum Area’, ‘course’, $args_curriculum_area_taxonomy ); to be: register_taxonomy( ‘curriculum-area’, ‘course’, $args_curriculum_area_taxonomy ); Also change this line ‘taxonomies’ => array( ‘curriculum_area’ ), to ‘taxonomies’ => array( ‘curriculum-area’ ), I forgot to say, remember … Read more
Try this piece of code for page template. I’ve used it on one of my projects. It outputs taxonomy term one by one with list of all posts with this term. (Just replace YOUR_TAXONOMY_SLUG to yours) <div id=”content”> <h2 class=”entry-title”><?php the_title(); ?></h2> <div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>> $mytaxonomy = get_terms(‘YOUR_TAXONOMY_SLUG’, array(“fields” => “names”)); … Read more
you can use the get_the_terms() function to get the terms of that post in a specific taxonomy: $terms = get_the_terms( $post->ID , ‘speaker’ ); //change speaker to whatever you call your taxonomy //then you can use just the first term $term_id = $terms[0]->term_id; and now you have the term id inside $term_id. update Once you … Read more
Nope. Not the WordPress way at least. You could probably make helper function (plain PHP realm in other words) to build instances of label arrays, however that would seriously hinder making strings translatable.