0

I need to return the taxonomy term ID based on the terms description. Is this possible?

I know the description along with the term ID is held within the wp_term_taxonomy table. However I was wondering whether I could retrieve it through a function rather than having to use wpdb.

0

I'm not aware of ready-made functions that support this, but you can easily construct a WP_Term_Query to do this. The following code is untested but should work:

$args = [
    'description__like' => 'the description you\'re searching for',
    'taxonomy'          => 'category',//or other taxonomy
    'fields'            => 'ids',
    'hide_empty'        => false,
];
$term_query = new WP_Term_Query($args);
foreach ($term_query->terms as $term) {
    // ID is in $term->term_id
}
  • 1
    wp_term_query - great - never knew of it's existence. Thanks very much. – user142553 Nov 12 '18 at 12:00
  • There are various _Query classes, always a good thing to check them out – kero Nov 12 '18 at 12:07

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.