首页 > 解决方案 > 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后,就出现了这个错误。

请问我需要修改或删除哪些部分才能丢失正在生成的数字标签?

这是标签加上它下面的数字的截图

标签: phphtmlwordpressbuddypress

解决方案


推荐阅读