wp_popular_terms_checklist
函数
wp_popular_terms_checklist ( $taxonomy, $default_term = 0, $number = 10, $display = true )
- 参数
-
-
(string)
$taxonomy
Taxonomy to retrieve terms from.- Required: 是
-
(int)
$default_term
Optional. Not used.- Required: 否
-
(int)
$number
Optional. Number of terms to retrieve. Default 10.- Required: 否
- Default: 10
-
(bool)
$display
Optional. Whether to display the list as well. Default true.- Required: 否
- Default: true
-
(string)
- 返回值
-
- (int[]) Array of popular term IDs.
- 定义位置
-
-
wp-admin/includes/template.php
, line 209
-
wp-admin/includes/template.php
- 引入
- 2.5.0
- 弃用
- –
Retrieves a list of the most popular terms from the specified taxonomy.
If the `$display` argument is true then the elements for a list of checkbox
“ elements labelled with the names of the selected terms is output.
If the `$post_ID` global is not empty then the terms associated with that
post will be marked as checked.
function wp_popular_terms_checklist( $taxonomy, $default_term = 0, $number = 10, $display = true ) {
$post = get_post();
if ( $post && $post->ID ) {
$checked_terms = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
} else {
$checked_terms = array();
}
$terms = get_terms(
array(
'taxonomy' => $taxonomy,
'orderby' => 'count',
'order' => 'DESC',
'number' => $number,
'hierarchical' => false,
)
);
$tax = get_taxonomy( $taxonomy );
$popular_ids = array();
foreach ( (array) $terms as $term ) {
$popular_ids[] = $term->term_id;
if ( ! $display ) { // Hack for Ajax use.
continue;
}
$id = "popular-$taxonomy-$term->term_id";
$checked = in_array( $term->term_id, $checked_terms, true ) ? 'checked="checked"' : '';
?>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。