【发布时间】:2017-08-21 23:57:27
【问题描述】:
我正在尝试使用 this script 在我的元框文件中添加变量而不是自定义字段 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 );
但是通过上面的例子,我得到了 注意:数组到字符串的转换在 /var/www/html/mytheme/wp-includes/formatting.php 在第 1025 行
因此,如果我添加没有可变元框的自定义字段,则可以正常工作,如下所示:
$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 );
我尝试过使用 print_r 但元框不保存。有什么方法可以使第一个代码工作吗?使用变量而不是自定义字段 ID?
【问题讨论】:
-
例如的内容是什么。
$redux['mytheme_videourl'];?通知说它是一个数组,但你只想拥有一个特定的元素。 -
$redux['mytheme_videourl'];是一个 redux 框架选项,它只是我的 redux / 主题设置面板中的一个字段。我想提供使自定义字段可变的可能性,就像你看到的那样,我从数据库中调用 global $redux 但是我只想在我的 metaboxes 文件中使用这些变量。Metaboxes 文件正在帖子编辑器下方创建自定义字段选项,通知也在帖子编辑器下方。 -
是的,我知道,但
$redux['mytheme_videourl'];是一个数组,而不是一个字符串。你能在某个地方做一个print_r($redux['mytheme_videourl']),在那里你可以看到它的内容吗?或者print_r($redux['mytheme_videourl'], true)作为描述或类似的,这样你就可以看到它的内容? -
是的,我尝试过使用 print_r,但是当我这样做时,自定义字段值会消失。
-
我要重新尝试
标签: php arrays wordpress meta-boxes