问题描述
如何向此联系表 7 分类法循环添加一个空的第一个值。我希望第一个显示的值为空(或带有自定义文本),接下来的值是通过我的分类法的循环值。
对此的一些解释也将不胜感激。谢谢!
function dynamic_select_list( $tag ) {
// Only run on select lists
if( 'select' !== $tag['type'] && ('select*' !== $tag['type']) ) {
return $tag;
} else if ( empty( $tag['options'] ) ) {
return $tag;
}
$term_args = array();
// Loop thorugh options to look for our custom options
foreach( $tag['options'] as $option ) {
$matches = explode( ':',$option );
if( ! empty( $matches ) ) {
switch( $matches[0] ) {
case 'taxonomy':
$term_args['taxonomy'] = $matches[1];
break;
case 'parent':
$term_args['parent'] = intval( $matches[1] );
break;
}
}
}
// Ensure we have a term arguments to work with
if( empty( $term_args ) ) {
return $tag;
}
// Merge dynamic arguments with static arguments
$term_args = array_merge( $term_args,array(
'hide_empty' => false,) );
$terms = get_terms( $term_args );
// Add terms to values
if( ! empty( $terms ) && ! is_wp_error( $term_args ) ) {
foreach( $terms as $term ) {
$tag['values'][] = $term->name;
}
}
return $tag;
}
add_filter( 'wpcf7_form_tag','dynamic_select_list',10 );
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)