function get_the_terms( $post, $taxonomy ) { $post = get_post( $post ); if ( ! $post ) { return false; } $terms = get_object_term_cache( $post->ID, $taxonomy ); if ( false === $terms ) { $terms = wp_get_object_terms( $post->ID, $taxonomy ); if ( ! is_wp_erro...
参数:`get_the_terms()` 需要两个参数,第一个是文章的ID,第二个是分类法的名称(例如 ‘category’、’post_tag’)。 性能:由于其通用性,`get_the_terms()` 在处理非分类的自定义分类法时可能不如专门针对分类的函数性能高。 如果你只需要处理标准的WordPress分类,并且想要一个简单直接的解决方案,`get_the_...
get_the_category和get_the_terms貌似都是用来获取分类信息的,前者使用方法简单,不带参数,后者使用方法 <?php get_the_terms( $id, $taxonomy ); ?> 例如:woocommerce中,获取当前产品页面的分类信息,前者居然无效,后者要使用 <?php get_the_terms( $id, 'product_cat'); 为什么要填写'product_cat',我...
有些说,您可以在循环外部使用get_terms,而只能在循环内部使用get_the_terms。 但并非如此,您也可以在循环外部使用get_the_terms(),例如: $categories = get_the_terms( $id, 'product_cat' ); 在get_the_terms中,您可以通过特定的post_id获取术语,但是在get_terms中,您可以获取一组...
function get_the_terms( $post, $taxonomy ) { $post = get_post( $post ); if ( ! $post ) { return false; } $terms = get_object_term_cache( $post->ID, $taxonomy ); if ( false === $terms ) { $terms = wp_get_object_terms( $post->ID, $taxonomy ); if ( ! is_wp_erro...
add_action('woocommerce_single_product_summary' , 'cat_type_before_title', 3); function cat_type_before_title() { global $post; $terms = wp_get_post_terms( get_the_ID(), 'product_cat', array( 'orderby' => 'parent' ) ); foreach ( $terms as $term ) { $term_link = get_te...
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有...
$terms(WP_Term[]|WP_Error) Array of attached terms, or WP_Error on failure. $post_id(int) Post ID. $taxonomy(string) Name of the taxonomy. Changelog Since 3.1.0Introduced. Where the hook is called get_the_terms() get_the_terms ...
Get the terms right.Presents a letter to the editor in reference to an article on the U.S. National Institute of Health and its state-of-the-science conference on hormone replacement therapy.EBSCO_bspDrug Topics
$post_terms = get_the_terms( $block->context['postId'], $attributes['term'] ); if ( is_wp_error( $post_terms ) || empty( $post_terms ) ) { return ''; } cc @david-binda Fix: return empty string instead of false Verified f3afb61 Contributor david-binda commented Oct ...