10 php arrays wordpress meta-boxes
我试图使用此脚本在我的metaboxes文件中添加变量而不是自定义字段ID
我在redux框架中添加了一些选项,以便更改自定义字段.
<?php
/*global from framework*/
global $redux;
/*custom fields options retrieved from redux framework*/
$custom_videourl = $redux['mytheme_videourl'];
$custom_duration = $redux['mytheme_duration'];
$custom_description = $redux['mytheme_desc'];
$fields = array(
array(
'label' => __( 'MP4/FLV & Youtube Url', 'framework' ),
'desc' => __( 'Here you can add videos with mp4 format', 'framework' ),
'id' => $custom_videourl,
'type' => 'text'
),
array(
'label' => __( 'Video Duration', 'framework' ),
'desc' => __( 'Example: 5:20', 'framework' ),
'id' => $custom_duration,
'type' => 'text'
),
array(
'label' => __( 'Video Description', 'framework' ),
'id' => $custom_description,
'desc' => __( 'Here you can write a description', 'framework' ),
'type' => 'editor'
)
);
$my_metaboxes = new custom_add_meta_box( 'mytheme_metaboxes', __( 'Video - Additional Information', 'framework' ), $fields, 'post', true );
Run Code Online (Sandbox Code Playgroud)
但是通过上面的例子,我在第1025行的/var/www/html/mytheme/wp-includes/formatting.php中得到了 注意:数组转换为字符串
因此,如果我添加自定义字段而没有变量元框,则工作正常,如下面的内容:
$fields = array(
array(
'label' => __( 'MP4/FLV & Youtube Url', 'framework' ),
'desc' => __( 'Here you can add videos with mp4 format', 'framework' ),
'id' => 'mytheme_videourl',
'type' => 'text'
),
array(
'label' => __( 'Video Duration', 'framework' ),
'desc' => __( 'Example: 5:20', 'framework' ),
'id' => 'mytheme_duration',
'type' => 'text'
),
array(
'label' => __( 'Video Description', 'framework' ),
'id' => 'mytheme_desc',
'desc' => __( 'Here you can write a description', 'framework' ),
'type' => 'editor'
)
);
$my_metaboxes = new custom_add_meta_box( 'mytheme_metaboxes', __( 'Video - Additional Information', 'framework' ), $fields, 'post', true );
Run Code Online (Sandbox Code Playgroud)
我尝试过使用print_r但是metaboxes没有保存.有没有办法让第一个代码工作?使用变量而不是自定义字段ID?
您的 redux 变量之一似乎很可能包含数组而不是字符串。知道了这一点,您只需要弄清楚它是哪一个,并找出您正在寻找的实际数据在哪里。
调试此问题的一种方法是将所有三个 redux 变量显式转换为字符串。(例如'id' => implode("***", $custom_videourl))。然后,一旦您弄清楚哪一个(或多个)是数组,您可能就会知道如何访问您真正想要的数据。
如果这不适合你,我建议将其添加到你的 wp-config.php 文件中define( 'WP_DEBUG_LOG', true ):
这将为您创建一个调试日志。然后您可以注销(例如error_log( print_r( $custom_videourl ));我相信它通常将 debug.log 文件存储在 wp-content 文件夹中。
| 归档时间: |
|
| 查看次数: |
1944 次 |
| 最近记录: |