0
votes

I'm trying to code a little Taxonomy-Filter for my Custom-Post-Type-Pages, Archives and Term-Pages. Therefore I try to find out, which taxonomy is used on current page.

For example: http://www.domain.de/taxonomy, or archive of custom-post-type like http://www.domain.de/portfolio

Example: I build a portfolio-page with custom post-type. I gave this the taxonomies "skills" and "category". On the page-portfolio.php and archive-portfolio.php there will be a filter with the terms of "skills" and "category".

$terms = get_the_terms($post->id, 'TAXONOMY_NAME'); should not fit, because, the filter should fit for many unknown Taxonomy and Custom-post-types. Also there is no fixed taxonomy-name available.

        $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
        $incname = $term->taxonomy;
        $args = array( 'hide_empty=0' );
        $terms = get_terms( $incname, $args );

        if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
            //do spomething
            else {
            //do spomething
            }
        }

The code above works only, if the current page is already a term-page (http://www.domain.de/taxonomy/term)

        $term = $wp_query->queried_object;
        $taxonomy = $term->taxonomy;
        $terms = get_terms($taxonomy);

        if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
            //do spomething
            else {
            //do spomething
            }
        }

The code above works only, if the current page is already a term-page (http://www.domain.de/taxonomy/term)

How can I get the taxonomies and (child-)terms of current post-type?

1
Did you find a solution on this?Antoine Henrich

1 Answers

0
votes

Have you looked at wp_get_post_terms()?(http://codex.wordpress.org/Function_Reference/wp_get_post_terms)

From your description, it looks like it should give you the terms you need.

HTH!

=C=