在 wp_tag_cloud 参数中包含来自自定义字段的值
Include the value from the custom field in the wp_tag_cloud arguments
使用短代码 [tagsListfoot]
,我在网站的地下室显示了一堆地标。现在看起来像这样:
add_shortcode( 'tagsListfoot', 'getTagListfoot' );
function getTagListfoot() {
global $post;
$args = array(
'taxonomy' => 'tags_type',
'order' => 'RAND',
'number' => '10',
);
wp_tag_cloud( $args );
}
每个标签都有一个自定义字段(2 个单选框 - “是”和“否”)。是否可以将自定义字段中的值添加到云参数?理想情况下,您应该只输出值为“yes”的标签。
我试过类似的方法,但没有用(
add_shortcode( 'tagsListfoot', 'getTagListfoot' );
function getTagListfoot() {
global $post;
$tag_footer = ( 'yes' == get_term_meta( $tag->term_id, 'pokazat-v-podvale' ) );
$args = array(
'taxonomy' => 'tags_type',
'order' => 'RAND',
'number' => '10',
'include' => $tag_footer,
);
wp_tag_cloud( $args );
}
感谢@CBroe 的提示
的确,也可以使用meta_query
来请求自定义字段的值。事情是这样的:
add_shortcode( 'tagsListfoot', 'getTagListfoot' );
function getTagListfoot() {
global $post;
$args = array(
'taxonomy' => 'tags_type',
'order' => 'RAND',
'number' => '10',
'meta_query' => array(
array(
'key' => 'show_in_foot',
'value' => 'yes',
'compare' => 'IN',
),
),
);
wp_tag_cloud( $args );
}
使用短代码 [tagsListfoot]
,我在网站的地下室显示了一堆地标。现在看起来像这样:
add_shortcode( 'tagsListfoot', 'getTagListfoot' );
function getTagListfoot() {
global $post;
$args = array(
'taxonomy' => 'tags_type',
'order' => 'RAND',
'number' => '10',
);
wp_tag_cloud( $args );
}
每个标签都有一个自定义字段(2 个单选框 - “是”和“否”)。是否可以将自定义字段中的值添加到云参数?理想情况下,您应该只输出值为“yes”的标签。
我试过类似的方法,但没有用(
add_shortcode( 'tagsListfoot', 'getTagListfoot' );
function getTagListfoot() {
global $post;
$tag_footer = ( 'yes' == get_term_meta( $tag->term_id, 'pokazat-v-podvale' ) );
$args = array(
'taxonomy' => 'tags_type',
'order' => 'RAND',
'number' => '10',
'include' => $tag_footer,
);
wp_tag_cloud( $args );
}
感谢@CBroe 的提示
的确,也可以使用meta_query
来请求自定义字段的值。事情是这样的:
add_shortcode( 'tagsListfoot', 'getTagListfoot' );
function getTagListfoot() {
global $post;
$args = array(
'taxonomy' => 'tags_type',
'order' => 'RAND',
'number' => '10',
'meta_query' => array(
array(
'key' => 'show_in_foot',
'value' => 'yes',
'compare' => 'IN',
),
),
);
wp_tag_cloud( $args );
}