Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在前端wit WP存储定位器上显示自定义元数据?_Javascript_Json_Wordpress_Google Maps - Fatal编程技术网

Javascript 如何在前端wit WP存储定位器上显示自定义元数据?

Javascript 如何在前端wit WP存储定位器上显示自定义元数据?,javascript,json,wordpress,google-maps,Javascript,Json,Wordpress,Google Maps,我想在商店信息(电子邮件下方)下方的信息窗口中添加自定义文本 我遵照以下指示: 因此,我在worpress主题的function.php文件中添加了以下内容: // adding my_textinput field add_filter( 'wpsl_meta_box_fields', 'custom_meta_box_fields' ); function custom_meta_box_fields( $meta_fields ) { $meta_fields[__( 'A

我想在商店信息(电子邮件下方)下方的信息窗口中添加自定义文本

我遵照以下指示:

因此,我在worpress主题的function.php文件中添加了以下内容:

// adding my_textinput field
add_filter( 'wpsl_meta_box_fields', 'custom_meta_box_fields' );

function custom_meta_box_fields( $meta_fields ) {

    $meta_fields[__( 'Additional Information', 'wpsl' )] = array(
        'phone' => array(
            'label' => __( 'Tel', 'wpsl' )
        ),
        'fax' => array(
            'label' => __( 'Fax', 'wpsl' )
        ),
        'email' => array(
            'label' => __( 'Email', 'wpsl' )
        ),
        'url' => array(
            'label' => __( 'Url', 'wpsl' )
        ),
        'my_textinput' => array(
            'label' => __( 'Textinput', 'wpsl' )
        )
    );

    return $meta_fields;
}

// add my_textinput in to the json response
function custom_frontend_meta_fields( $store_fields ) {

    $store_fields['wpsl_my_textinput'] = array( 
        'name' => 'my_textinput',
        'type' => 'text'
    );

    return $store_fields;
}


// show my_textinput into the frontend on info window
add_filter( 'wpsl_info_window_template', 'custom_info_window_template' );

function custom_info_window_template() {

    global $wpsl_settings, $wpsl;

    $info_window_template = '<div data-store-id="<%= id %>" class="wpsl-info-window">' . "\r\n";
    $info_window_template .= "\t\t" . '<p>' . "\r\n";
    $info_window_template .= "\t\t\t" .  wpsl_store_header_template() . "\r\n";  
    $info_window_template .= "\t\t\t" . '<span><%= address %></span>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<% if ( address2 ) { %>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<span><%= address2 %></span>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<% } %>' . "\r\n";
    $info_window_template .= "\t\t\t" . '<span>' . wpsl_address_format_placeholders() . '</span>' . "\r\n";
    $info_window_template .= "\t\t" . '</p>' . "\r\n";

    $info_window_template .= "\t\t" . '<% if ( phone ) { %>' . "\r\n";
    $info_window_template .= "\t\t" . '<span><strong>' . esc_html( $wpsl->i18n->get_translation( 'phone_label', __( 'Phone', 'wpsl' ) ) ) . '</strong>: <%= formatPhoneNumber( phone ) %>(1)</span>' . "\r\n";
    $info_window_template .= "\t\t" . '<% } %>' . "\r\n";
    $info_window_template .= "\t\t" . '<% if ( fax ) { %>' . "\r\n";
    $info_window_template .= "\t\t" . '<span><strong>' . esc_html( $wpsl->i18n->get_translation( 'fax_label', __( 'Fax', 'wpsl' ) ) ) . '</strong>: <%= fax %>(2)</span>' . "\r\n";
    $info_window_template .= "\t\t" . '<% } %>' . "\r\n";
    $info_window_template .= "\t\t" . '<% if ( email ) { %>' . "\r\n";
    $info_window_template .= "\t\t" . '<span><strong>' . esc_html( $wpsl->i18n->get_translation( 'email_label', __( 'Email', 'wpsl' ) ) ) . '</strong>: <%= formatEmail( email ) %>(3)</span>' . "\r\n";
    $info_window_template .= "\t\t" . '<% } %>' . "\r\n";

    /**
     * Include the data from a custom field called 'my_textinput'.
     * 
     * Before you can access the 'my_textinput' data in the template, 
     * you first need to make sure the data is included in the JSON output.
     * 
     * You can make the data accessible through the wpsl_frontend_meta_fields filter.
     * 
     * 
     */

    $info_window_template .= "\t\t" . '<% if ( my_textinput ) { %>' . "\r\n";
    $info_window_template .= "\t\t" . '<p><%= my_textinput %></p>' . "\r\n";
    $info_window_template .= "\t\t" . '<% } %>' . "\r\n";

    $info_window_template .= "\t\t" . '<%= createInfoWindowActions( id ) %>' . "\r\n";
    $info_window_template .= "\t" . '</div>' . "\r\n";

    return $info_window_template;
}
//添加我的文本输入字段
添加过滤器('wpsl_meta_box_字段','custom_meta_box_字段');
函数自定义\元\框\字段($meta\字段){
$meta_字段[uuu('Additional Information','wpsl')]=数组(
'电话'=>阵列(
'label'=>\('Tel','wpsl')
),
“传真”=>阵列(
'label'=>\('Fax','wpsl')
),
'电子邮件'=>数组(
'label'=>\('Email','wpsl')
),
'url'=>数组(
'label'=>\('Url','wpsl')
),
“我的文本输入”=>数组(
'label'=>
)
);
返回$meta_字段;
}
//将my_textinput添加到json响应中
函数自定义\前端\元\字段($store\字段){
$store_fields['wpsl_my_textinput']=数组(
'name'=>'my_textinput',
'键入'=>'文本'
);
返回$store_字段;
}
//在前端的信息窗口中显示我的文本输入
添加过滤器(“wpsl信息窗口模板”、“自定义信息窗口模板”);
函数自定义\信息\窗口\模板(){
全局$wpsl_设置,$wpsl;
$info\u window\u template=''。\r\n;
$info\u window\u template.=“\t\t”。“”。“\r\n”;
$info\u window\u template.=“\t\t\t”.wpsl\u store\u header\u template()。”\r\n”;
$info\u window\u template.=“\t\t\t”。”。“\r\n”;
$info\u window\u template.=“\t\t\t”。”。“\r\n”;
$info\u window\u template.=“\t\t\t”。”。“\r\n”;
$info\u window\u template.=“\t\t\t”。”。“\r\n”;
$info\u window\u template.=“\t\t\t”。“\r\n”;
$info\u window\u template.=“\t\t”

”。“\r\n”; $info\u window\u template.=“\t\t”。”。“\r\n”; $info\u window\u template.=“\t\t””.esc\u html($wpsl->i18n->get\u translation('phone\u label','phone','wpsl'))。:(1)“\r\n”; $info\u window\u template.=“\t\t”。”。“\r\n”; $info\u window\u template.=“\t\t”。”。“\r\n”; $info\u window\u template.=“\t\t””.esc\u html($wpsl->i18n->get\u translation('fax\u label','fax','wpsl'))。:(2)“\r\n”; $info\u window\u template.=“\t\t”。”。“\r\n”; $info\u window\u template.=“\t\t”。”。“\r\n”; $info\u window\u template.=“\t\t””.esc\u html($wpsl->i18n->get\u translation('email\u label','email','wpsl'))。:(3)“\r\n”; $info\u window\u template.=“\t\t”。”。“\r\n”; /** *包括来自名为“my_textinput”的自定义字段的数据。 * *在访问模板中的“my_textinput”数据之前, *首先需要确保数据包含在JSON输出中。 * *您可以通过wpsl_frontend_meta_字段过滤器访问数据。 * * */ $info\u window\u template.=“\t\t”。”。“\r\n”; $info\u window\u template.=“\t\t”。“

”。“\r\n”; $info\u window\u template.=“\t\t”。”。“\r\n”; $info\u window\u template.=“\t\t”。”。“\r\n”; $info\u window\u template.=“\t.”“\r\n”; 返回$info\u窗口\u模板; }
当我添加以下代码时(几乎是结尾),信息窗口不会显示:

$info_window_template .= "\t\t" . '<% if ( my_textinput ) { %>' . "\r\n";
$info_window_template .= "\t\t" . '<p><%= my_textinput %></p>' . "\r\n";
$info_window_template .= "\t\t" . '<% } %>' . "\r\n";
$info\u window\u模板=“\t\t”。”。“\r\n”;
$info\u window\u模板=“\t\t”。” 

'。“\r\n”; $info\u window\u模板=“\t\t”。”。“\r\n”;
我在DevTool控制台上遇到以下错误:

Uncaught ReferenceError: my_textinput is not defined
    at eval (eval at m.template (underscore.min.js?ver=1.8.3:5), <anonymous>:52:2)
    at c (underscore.min.js?ver=1.8.3:5)
    at H (wpsl-gmap.min.js?ver=2.2.15:1)
    at _.ze.<anonymous> (wpsl-gmap.min.js?ver=2.2.15:1)
    at Object.trigger ...
未捕获引用错误:未定义my_textinput
在eval时(在m.template时eval(下划线.min.js?ver=1.8.3:5),:52:2)
在c处(下划线.min.js?ver=1.8.3:5)
H时(wpsl gmap.min.js?ver=2.2.15:1)
在ze。(wpsl gmap.min.js?ver=2.2.15:1)
在Object.trigger。。。

如何确保数据包含在JSON输出中?

需要使用3个过滤器来实现它

  • wpsl_meta_box_字段
  • wpsl_前端_元_字段
  • wpsl_信息_窗口_模板
  • 用于在前端json中添加自定义字段的wpsl_前端_元_字段筛选器

    上述错误意味着自定义字段my_textinput未添加到前端json中。请检查您是否正在使用缓存。如果是,请从设置中清除缓存。为此,请导航至“存储定位器设置”页面中的“工具”部分,然后清除“存储定位器瞬态缓存”。