我想创建一个短代码来返回一个值字符串,这些值是术语名称。所以我可以用它在插件中传递数据。以前有人破解过这个吗?
/**
* Custom shortcode to get terms for the Formidable plugin
*/
function ALC_post_terms_by_id( $term, $atts ) {
global $post;
$alc_Terms = wp_get_post_terms( $post->ID, $term, \'orderby=name&hide_empty=0\' );
$term_array = array();
foreach ($alc_Terms as $alc_Term) {
$term_array[] = $alc_Term->name;
}
// $atts = shortcode_atts( $term_array() ), $atts );
return $term_array();
}
add_shortcode( \'term_by_id\', \'ALC_post_terms_by_id\' );
<小时>
New attempt
这是我使用的短代码:
[get_terms_by_taxonomy taxonomy="bouwjaar"]
这是HeadMedic在评论中建议的新功能
/**
* Custom shortcode to get terms for the Formidable plugin
*/
function ALC_post_terms_by_taxonomy( $atts ) {
// return $atts[\'taxonomy\'];
$taxonomyTerms = wp_get_post_terms( $post->ID, $atts[\'taxonomy\'], \'orderby=name&hide_empty=0\' );
$term_array = array();
foreach ($taxonomyTerms as $taxonomyTerm) {
$term_array[] = $taxonomyTerm->name;
}
return $term_array; // returns "Array"
// return implode( \', \', $term_array );
// implode returns "nothing"
}
add_shortcode(\'get_terms_by_taxonomy\', \'ALC_post_terms_by_taxonomy\');
SO网友:Remi
这是通过快捷码按分类法获取帖子术语的解决方案:
/**
* Custom shortcode to get terms
*/
function ALC_post_terms_by_taxonomy( $atts ) {
global $post;
$taxonomyTerms = wp_get_post_terms( $post->ID, $atts[\'taxonomy\'], \'orderby=name&hide_empty=0\' );
$term_array = array();
foreach ($taxonomyTerms as $taxonomyTerm) {
$term_array[] = $taxonomyTerm->name;
}
return implode( \', \', $term_array );
}
add_shortcode(\'get_terms_by_taxonomy\', \'ALC_post_terms_by_taxonomy\');
您可以通过以下短代码使用它:
[get_terms_by_taxonomy taxonomy="taxonomyname"]