admin管理员组文章数量:1130349
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.
1 Answer
Reset to default 0I'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
}
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.
1 Answer
Reset to default 0I'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
}
本文标签: taxonomyGet Term ID by Description
版权声明:本文标题:taxonomy - Get Term ID by Description 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749190903a2330164.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论