wp_get_object_terms( int|array $object_ids, string|array $taxonomies, array|string $args = array() ) Retrieves the terms associated with the…
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); // 用逗号分隔不同的分类链接 $separator = ', '; if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) { $term_ids = implode( ',' , $post_terms ); $terms = wp_list_ca...
php$taxonomy='category';// 获取某篇文章的分类id$post_terms=wp_get_object_terms($post->ID,$taxonomy,array('fields'=>'ids'));// 用逗号分隔不同的分类链接$separator=', ';if(!empty($post_terms)&&!is_wp_error($post_terms)){$term_ids=implode(',',$post_terms);$terms=wp_list_categor...
}// if we've got an array, make it a comma delimited stringif(isset($cache_data) && $cache_data != wp_cache_get('mentions', $post->ID)) {wp_set_object_terms($post->ID, $users_to_add,'mentions',true);// tag the post.wp_cache_set('mentions', $cache_data, $post->ID); ...
根据父-子关系来排序文章的分类。类似于 get_the_category_list() 函数(根据名称排序分类)。这个例子必须使用内循环。 $taxonomy= 'category';//Get the term IDs assigned to post.$post_terms= wp_get_object_terms($post->ID,$taxonomy,array( 'fields' => 'ids') );//Separator between links.$separ...
$post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); // 用逗号分隔不同的分类链接 $separator = ', '; if ( !empty( $post_terms ) && !is_wp_error( $post_terms ) ) { $term_ids = implode( ',' , $post_terms ); $terms = wp_list_ca...
因为wp_set_post_terms使用intval函数在处理层级关系的分类模式时对$terms数组中的每个元素做了强类型转换。所以也为了防止冲突,他也直接接受 IDs 方式的参数。 wp_set_object_terms也可以给给文章设置分类,但是他就没有类型转换的功能。这也是要注意的一点。
'terms' => array( 'post-format-quote' ) ) ) ); $query = new WP_Query( $args ); 本例为查询“在quotes(分类的slug)分类”下或“post_format”为“post-format-quote”的文章(’post_type’ => ‘post’)。 搜索 WP_Query也提供了一个简单的基于文关键词的搜索功能,参考下面的例子: ...
‘tax_input:等效于为数组中的每个自定义分类法调用 wp_set_post_terms(),如果当前用户没有设置自定义分类法的权限,就必须使用 wp_set_object_terms() 代替了。 ‘page_template’:如果 post_type 为‘page’,将尝试设置页面,如果设置失败,此函数将返回一个 WP_Error 对象或 0,然后在最终操作之前停止。如果...
您可以使用get_the_terms。试试下面的代码。