将wp_editor添加到用户创建的元数据库

时间:2016-01-12 05:26:58

标签: php jquery wordpress wp-editor

所以,我设置了一个插件,允许我的客户端能够添加带有按钮的元框,从而添加更具动态性的新内容,以及其他标题/标题等。这就是它现在的设置方式...

function Print_price_fileds($cnt, $p = null) {
if ($p === null){
    $a = $b = $c = '';
}else{
    $a = $p['n'];
    $b = $p['d'];
    $c = $p['p'];
}
return  <<<HTML
<li>
  <input type="text" name="additional_content[$cnt][d]" size="50" value="$b" placeholder="Title"/>

  <textarea name="additional_content[$cnt][p]" class="wp-editor-area" style="height: 320px; width: 100%; margin-top: 37px;" autocomplete="off" placeholder="Content">$c</textarea>
  <span class="remove submitdelete deletion">Remove</span>
</li>
HTML
;
}



function additional_content_boxes(){
 global $post;

  $data = get_post_meta($post->ID,"additional_content",true);

  echo '<div>';
  echo '<ul id="additional_content_items">';
  $c = 0;
    if (count($data) > 0){
        foreach((array)$data as $p ){
            if (isset($p['p']) || isset($p['d'])|| isset($p['n'])){
                echo Print_price_fileds($c,$p);
                $c = $c +1;
            }
        }

    }
    echo '</ul>';

    ?>
        <span id="here"></span>
        <span class="add button button-primary button-large"><?php echo __('Add Additional Content'); ?></span>
        <script>
            var $ =jQuery.noConflict();
                $(document).ready(function() {
                var count = <?php echo $c - 1; ?>; // substract 1 from $c
                $(".add").click(function() {
                    count = count + 1;
                   $('#additional_content_items').append('<? echo implode('',explode("\n",Print_price_fileds('count'))); ?>'.replace(/count/g, count));
                    return false;
                });
                $(".remove").live('click', function() {
                    $(this).parent().remove();
                });
            });
        </script>
        <style>#additional_content_items {list-style: none; padding-bottom: 20px; border-bottom: 1px solid #ddd; margin-top: 30px; display: block;}</style>
    <?php
    echo '</div>';
}

现在这很好用,但我希望能够将wp_editor添加到其他元数据库中,从而替换<textarea>。我怎样才能做到这一点?

谢谢你们。 Ĵ

1 个答案:

答案 0 :(得分:0)

所以,我接受了Noman的建议,我正在使用Advanced Custom Fields插件。不知道为什么我之前没有听说过,因为它很完美。谢谢大家!

https://wordpress.org/plugins/advanced-custom-fields/