wordpress如何在数组中添加wp_editor

Sye*_*een 10 php wordpress redux-framework

我的wordpress代码中有一个小问题我需要在我的页面中显示wordpress wp_editor,其中包含值数组.值定义如下

    $fields[] = array(
        'name' => __('Class', 'my-theme'),
        'desc' => __('', 'my-theme'),
        'id' => 'class'.$n,
        'std' => ( ( isset($class_text[$n]['class']) ) ? $class_text[$n]['class'] : '' ),
        'type' => 'text');
Run Code Online (Sandbox Code Playgroud)

当我像上面的数组一样定义我的wp_editor时,它不会显示我想要的位置.相反,所有编辑器都显示在所有页面中的任何内容之前的顶部.

我为编辑器尝试了以下一组数组:

    $fields[] = array(
        'name' => __('My Content', 'my-theme'),
        'id' => 'sectioncontent'.$n,
        'std' => ( ( isset($class_text[$n]['content']) ) ? $class_text[$n]['content'] : '' ),
        'type' => wp_editor( '', 'sectioncontent'.$n ));
Run Code Online (Sandbox Code Playgroud)

附上我的问题的形象:

在此输入图像描述

Tou*_*afi 4

原因

默认情况下,wp_editor打印文本区域,这就是为什么您不能将其分配给任何变量或数组。

解决方案

您可以使用php 的输出缓冲来获取变量中的打印数据,如下所示:

ob_start(); // Start output buffer

// Print the editor
wp_editor( '', 'sectioncontent'.$n );

// Store the printed data in $editor variable
$editor = ob_get_clean();

// And then you can assign that wp_editor to your array.

$fields[] = array(
        'name' => __('My Content', 'my-theme'),
        'id' => 'sectioncontent'.$n,
        'std' => ( ( isset($class_text[$n]['content']) ) ? $class_text[$n]['content'] : '' ),
        'type' => $editor); // <-- HERE
Run Code Online (Sandbox Code Playgroud)