[英]How can I get WordPress to pull all description metadata fields without knowing their names or length?
How can I get WordPress to find and display all of the descriptions in use for a user?如何让 WordPress 找到并显示用户使用的所有描述? Typically, a user on our site will have a description in 2-3 languages.
通常,我们网站上的用户会有 2-3 种语言的描述。 The additional description fields in other languages are created by a plugin (and manually filled in by our editors).
其他语言的附加描述字段由插件创建(并由我们的编辑手动填写)。 Currently, ANOTHER plugin uses this code to display the main description for a user:
目前,另一个插件使用此代码来显示用户的主要描述:
$biography = get_the_author_meta( 'description', $user->user_id )
However, I need it to pull ALL description fields such as:但是,我需要它来提取所有描述字段,例如:
$biography = get_the_author_meta( 'description', $user->user_id ) . $biography = get_the_author_meta( 'description_zh', $user->user_id )
But this is clunky, and I won't know ahead of time how many languages will be added to the site.但这很笨拙,我不会提前知道网站将添加多少种语言。 I thought maybe something like this might work, but no luck:
我想也许这样的事情可能会奏效,但没有运气:
$biography = get_the_author_meta( 'description.*', $user->user_id )
I'm new to PHP, so any help much appreciated!我是 PHP 的新手,所以非常感谢任何帮助!
$bio_meta = (array)get_user_meta( $user->user_id );
foreach ( $bio_meta as $key => $value_array ) {
if ( strpos( $key, 'description' ) !== false ) {
$description_values[] = $value_array[0];
}
}
$biography = implode( ' ', $description_values );
Turning the meta results into an array makes life easier, then just check each key that begins with "description."将元结果转换为数组可以让生活更轻松,然后只需检查以“描述”开头的每个键。
If you wanted the output to include the key, you could change如果您希望输出包含密钥,则可以更改
$description_values[] = $value_array[0];
into this:进入这个:
$description_values[] = array( $key => $value_array[0] );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.