【发布时间】:2021-07-22 04:57:58
【问题描述】:
尝试将自定义帖子类型分类 (property_type) 输出为简码。在它应该输出分类的那一刻,它只输出单词 Array。对 php 很陌生,所以可能是我遗漏了一些简单的东西,或者完全找错了树。
代码是:
function prop_type_shortcode() {
$terms = wp_get_post_terms($post->ID, 'property_type');
if ($terms) {
$out = array();
foreach ($terms as $term) {
$out[] = '<a class="' .$term->slug .'" href="' .get_term_link( $term->slug, 'property_type') .'">' .$term->name .'</a>';
}
echo join( ', ', $out );
}
return $terms;
}
add_shortcode('type', 'prop_type_shortcode');
提前感谢您的帮助。
【问题讨论】:
标签: php wordpress shortcode custom-taxonomy