1

How do i get the ID from the current custom taxonomy (category) the user is browsing?

It uses a custom post type called "products" The categories are called "pcategories"

With normal categories i would get it like this:

<?php if ( is_category() )  
{  
    $cat= get_category( get_query_var( 'cat' ) );
    $cat_id = $cat->cat_ID;
    $categorytable = myrp_api_comparison_table( $category = $cat_id, $number = null, $visit_text = "Visit Text", $image_set = null, $custom_fields = null, $rating_categories = null, $return = false );
    if(empty($categorytable))
    {} else 
    {           
    echo $categorytable;
    } 
} 
?>

So how would i do this with custom taxonomies?

If i do:

<pre><?php print_r($wp_query->query_vars); ?></pre>

I get:

Array
(
[pcategory] => televisies
[error] => 
[m] => 0
[p] => 0
[post_parent] => 
[subpost] => 
[subpost_id] => 
[attachment] => 
[attachment_id] => 0
[name] => 
[static] => 
[pagename] => 
[page_id] => 0
[second] => 
[minute] => 
[hour] => 
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] => 
[tag] => 
[cat] => 
[tag_id] => 
[author_name] => 
[feed] => 
[tb] => 
[paged] => 0
[comments_popup] => 
[meta_key] => 
[meta_value] => 
[preview] => 
[s] => 
[sentence] => 
[fields] => 
[category__in] => Array
    (
    )

[category__not_in] => Array
    (
    )

[category__and] => Array
    (
    )

[post__in] => Array
    (
    )

[post__not_in] => Array
    (
    )

[tag__in] => Array
    (
    )

[tag__not_in] => Array
    (
    )

[tag__and] => Array
    (
    )

[tag_slug__in] => Array
    (
    )

[tag_slug__and] => Array
    (
    )

[ignore_sticky_posts] => 
[suppress_filters] => 
[cache_results] => 1
[update_post_term_cache] => 1
[update_post_meta_cache] => 1
[post_type] => 
[posts_per_page] => 10
[nopaging] => 
[comments_per_page] => 50
[no_found_rows] => 
[taxonomy] => pcategory
[term] => televisies
[order] => DESC
1

I fixed it by using the following code:

$current_term = $wp_query->get_queried_object();    
$termid = $current_term->term_id;

Works quite well

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.