$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>taxonomy - Get Term ID by Description|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

taxonomy - Get Term ID by Description

matteradmin7PV0评论

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
}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far