php - WordPress PHP 'printf' 给出两个值
问题描述
我正在运行带有 BuddyPress 和 BuddyPress XProfile 插件的 WordPress 4.9.6。
XProfile 正在获取用户位置并将其作为个人资料中的超链接返回,以搜索具有相同位置标签的站点的其余部分。
我遇到的问题是 PHP 脚本返回的位置加上一个在 69、76 和 22 之间变化的数字。
这是我正在运行以获取位置的代码:
/**
* Modify the appearance of value.
*
* @param string $field_value Original value of field.
* @param int $field_id Id of field.
*
* @return string Value formatted
*/
public static function display_filter( $field_value, $field_id = 0 ) {
if ( empty( $field_value ) ) {
return;
}
$term_id = absint( $field_value );
$tax = self::get_selected_taxonomy( $field_id );
$term = get_term( $term_id, $tax );
if ( ! $term || is_wp_error( $term ) ) {
return '';
}
return printf( '<a href="%1$s">%2$s</a>', esc_url( get_term_link( $term, $tax ) ), esc_html( $term->name ) );
}
/**
* Get the terms content.
*
* @param int $field_id field id.
*
* @return string
*/
public static function get_selected_taxonomy( $field_id ) {
if ( ! $field_id ) {
return '';
}
return bp_xprofile_get_meta( $field_id, 'field', 'selected_taxonomy', true );
}
}
我从 sprintf 更改为 printf,因为它返回了完整的 HTML 代码。自从改成printf后,就出现了这个错误。
请问我需要修改或删除哪些部分才能丢失正在生成的数字标签?
解决方案
推荐阅读
- javascript - 从 ANGULARJS 中的 URL 中删除 #
- redis - 在分布式系统中选择哪种复制机制?
- python - 仅在 python 中使用 CSV 模块对 CSV 文件中的文本进行部分匹配
- node.js - 在 node/express 应用程序上键入控制器时出现问题
- java - 如何在 Android 中修复密钥长度 256 位
- python - Pandas:用最后一个可用值和一个标志填充空值
- python - 姜戈。如何为引导崩溃制作循环
- cassandra-3.0 - 无法更改 cassandra 列的数据类型
- python - 在 Google Colab 中打开 json 文件时显示错误
- javascript - 类型错误:无法读取未定义的属性“名称”|| 文件上传问题