Bardsworth
Bardsworth

Reputation: 408

Wordpress Taxanomy get term_id from slug

I know the slug and name of the Taxanomy that i want.

The Category is "portfolio_category" and the slug i'm trying to get the id is "elementary_school".

I want this because i need the id to get all the terms within elementary_school. which i've hardcoded like this. I don't want to hardcode that 24 instead i want to get the id dynamically from the slug in question.

$terms = get_terms( 'portfolio_category', array(
        'orderby' => 'id',
        'parent' => '24',
    )
);

Upvotes: 0

Views: 354

Answers (1)

Jared
Jared

Reputation: 758

Is this what you're looking for?

$parentTerm=get_term_by('slug','elementary_school','portfolio_category');
$terms=get_terms('portfolio_category',array(
    'orderby'=>'id',
    'parent'=>intval($parentTerm->term_id)
));

Upvotes: 1

Related Questions