taxonomy - Get Term ID by Description

admin2025-06-06  9

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.

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.

Share Improve this question edited Nov 12, 2018 at 11:26 kero 6,3501 gold badge25 silver badges34 bronze badges asked Nov 12, 2018 at 11:19 user142553user142553 212 silver badges9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749190928a317124.html

最新回复(0)