1

I have a custom post type called Case Studies, which I am then pulling out and displaying all on one page. Each Case Study has a few standard sections, and I want a separate editor for each section.

For pages with multiple sections, I have been using MultiEdit, which works fine. However, it only works on pages so it isn't an option for this.

How would I do this for my custom post type? Or am I approaching the problem wrong?

  • I took a quick look at the plugin's source and the "page only" functionality looks to be hard coded. I'd ask the plugin author. – s_ha_dum May 7 '14 at 14:17
  • I'm not asking for help with the plugin! I'm aware it's hard coded, and I don't really want to fork it just for this. I'm asking if there is another way. – callumacrae May 7 '14 at 14:19
  • That is not clear from your question. I can reopen but please edit the question to make your point more clear. There are several related questions already answered. See if any of those help. – s_ha_dum May 7 '14 at 14:22
  • I've looked through the first few pages, and I've done my own searches earlier, and I could only find similar-but-not-close-enough questions. I edited my question to make it clearer. – callumacrae May 7 '14 at 14:24
  • 1
    Seems like you just need to add_meta_box() coupled with `wp_editor(). There are also several metabox plugins/solutions out there that will handle this for you, such as Metabox and Advanced Custom Fields. – helgatheviking May 7 '14 at 14:38
2

You can use Advanced Custom Fields to Achieve this.

Check it out here

You can add custom fields with full editor capabilities and specific fields like images, text, number, links, etc. You can also show these fields only for your custom post type by creating a field group and setting the 'show only if' to your custom post type.

It's a very versatile and handy plugin and I use it on all my projects. Makes it easier to manage and update custom fields with almost no coding.

|improve this answer|||||
  • Wish I'd seen this earlier! I've already done it using one of the other answers, but I think this would have been the better answer. – callumacrae May 9 '14 at 10:25
1

MultiEdit support for custom post types:

Here's one way to add the multiple content sections to a custom post type edit screen:

MultiEdit support for custom post types

Demo plugin:

You can use the following demo plugin, as an extension to the Page.ly MultiEdit plugin, to add support for custom post types:

<?php
/**
 * Plugin Name: MultiEdit support for custom post type
 * Description: You must have the Page.ly MultiEdit plugin installed.
 * Plugin URI:  http://wordpress.stackexchange.com/a/143688/26350
 * Author:      birgire
 * Version:     0.0.1 
 */

add_action( 'load-post.php', 'wpse_143674_init' );

function wpse_143674_init()
{
    //--------------------------------
    // EDIT this setup to your needs:
    //
    $args = array( 
        'post' => array( 'Bottom', 'Center', 'Top' ), 
        'news' => array( 'Left', 'Right' ), 
    );

    $m = new WPSE_Multi_Edit_CPT( $args );
    $m->init();
}

/**
 * Class WPSE_Multi_Edit_CPT
 */
class WPSE_Multi_Edit_CPT
{ 
    protected $args      = array();
    protected $screen_id = '';

    public function __construct( $args = array() )
    {
        $this->args = $args;
    }

    public function init()
    {
        $this->screen_id = get_current_screen()->id;

        if( function_exists( 'multieditAdminHeader' )                        // check if Multi Edit plugin is installed
            && 0 < count( $this->args )                                      // check if input arguments exists
            && 'page' !== $this->screen_id                                   // dont' want 'page' post type
            && in_array( $this->screen_id, array_keys( $this->args ), TRUE )  // match input arguments
        )
            add_action ( 'admin_footer', array( $this, 'do_multi_meta'), 1 );    
    }

    public function do_multi_meta() 
    {
        global $post;

        // Multi content sections for the current post type:
        $multi = ( isset( $this->args[$this->screen_id] ) ) ? $this->args[$this->screen_id] : array();

        // Load scripts:
        multieditAdminHeader();

        // We have multiedit zones, load js and css load
        add_action ( 'edit_page_form',     'multieditAdminEditor', 1 );
        add_action ( 'edit_form_advanced', 'multieditAdminEditor', 1 );

        // Current post meta:
        $meta = has_meta( $post->ID );

        // What tabs to display:
        $present = array();
        foreach( $meta as $k => $v )
        {
            if( in_array( $region = str_ireplace( 'multiedit_','', $v['meta_key'] ), $multi, TRUE ) ):
                $present[$region] =  TRUE;
            else:
                unset( $meta[$k] );
            endif;          
        }

        //Draw HTML:
        drawMultieditHTML( $meta, $present );

        // If custom field is not declared yet, create one with update_post_meta 
        foreach( $multi as $region )
        {
            if( ! isset( $present[$region] ) ) 
                update_post_meta( $post->ID, 'multiedit_' . $region, '' );
        }       
    }

} // end class

Add the above code to the file /wp-content/plugins/multiedit-cpt/multiedit-cpt.php and activate it.

You just have to edit the setup to your needs:

    $args = array( 
        'post' => array( 'Bottom', 'Center', 'Top' ), 
        'news' => array( 'Left', 'Right' ), 
    );

Hope this helps.

|improve this answer|||||
  • This works, and it's pretty much what I ended up doing. I had a problem where I couldn't get the multieditDisplay function working on non-posts, so I had to call the custom fields directly. – callumacrae May 9 '14 at 10:28
  • Happy to hear that. I think this single array setup is more flexible than the template file parsing in the original plugin. – birgire May 9 '14 at 10:42
0

It depends on how your level of coding is.

If you use a plugin to create your custom post type you will have to look for a plugin that uses wp_editor or another rich text editor like TinyMCE.

If you create your Custom Post Types yourself you can use

  • wp_editor instead of a textarea.

    <?php wp_editor( $content, $editor_id, $settings = array() ); ?> 
    
  • or attach TinyMCE or another rich text editor to your text areas.

    <script type="text/javascript src="<your installation path>/tinymce/tinymce.min.js"/>
    <script type="text/javascript">
    tinymce.init({
        selector: "textarea"
     });
    </script>
    
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.