D
D
Danil Ostapenko2022-04-16 18:09:22
WordPress
Danil Ostapenko, 2022-04-16 18:09:22

How to check if there is a custom taxonomy created?

Good day, tell me, I want to check if there is a taxonomy 'test' if there is then use its ID if not then create and get its ID

$mainTag = 'test';
    $mainTag_srch = get_term_by( 'slug', $mainTag, 'applicationstag' );

    if(empty($mainTag_srch)==TRUE){
        $mainTag = wp_insert_term($mainTag,'applicationstag');
        $mainTag_ID = $mainTag['term_id'];
    }else {
        $mainTag_ID = $mainTag_srch['term_id'];
    }


If there is no taxonomy, it creates all the rules and gets its ID, but if it exists, then the code stops (as if the break is triggered), it feels like I didn’t collect the verification conditions correctly, tell me what’s wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2022-04-16
@Arh1diablo

https://developer.wordpress.org/reference/function...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question