Support » Plugins » How can I use the tinyMCE editor for fields in my Custom Post Type?

  • Resolved ancawonka

    (@ancawonka)


    I’m creating a custom post type that has a couple of fields for which I’d like to use the tinyMCE editor (so that users can add bullet lists, bold text, and so forth).

    Does anyone have pointers for how to do this?

    I found this post: http://wordpress.org/support/topic/331589?replies=2, which shows how one can add the mceEditor class to a text box using JQuery. Is this what I should be doing, or is there an easier way?

    Thanks,

    Anca.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Bump. I second this question. @ancawonka any chance you found a solution?

    Thread Starter ancawonka

    (@ancawonka)

    I have not found a solution. I’ll let you know once I do, it’s still on my list!

    as per your link, I was able to add it into my custom post type metabox with:

    <script type="text/javascript">
    jQuery(document).ready(function() {
    	jQuery("#blurb").addClass("mceEditor");
    	if ( typeof( tinyMCE ) == "object" &&
    		 typeof( tinyMCE.execCommand ) == "function" ) {
    		tinyMCE.execCommand("mceAddControl", false, "blurb");
    	}
    });
    </script>
    
    <textarea class="" name='blurb' id='blurb'></textarea>

    I haven’t found anything simpler, but that works

    Not sure if I’m missing something here but I just insert a metabox with a textarea and set its class to ‘theEditor’. TinyMCE is applied to every textarea that has the class ‘theEditor’.

    <textarea class=”theEditor” name=’blurb’ id=’blurb’></textarea>

    @wpsites: you’ve just made my day! Thank you, thank you, thank you!

    Thanks @wpsites. This is super-easy and really made things easier. I appreciate it.

    psydney

    (@psydney)

    When I set the class to ‘theEditor’, TinyMCE is applied to the textareas, but the p tags within it’s content get stripped out when I post/update. All other tags remain, such as a tags, b tags, etc.

    The only way I can prevent the p tags from not being stripped out is to add this to my functions file:

    add_filter('tiny_mce_before_init', 'change_mce_options');
    function change_mce_options( $init ) {
    	$init['plugins'] = false; //true works as well
    }

    I don’t know why it works… I only put it there because I don’t want to display plugin buttons.

    As of WordPress 3.1, adding $init['plugins'] causes the following error:

    “pl.split is not a function”

    It seems like it’s preventing tinymce from initializing. Any suggestions?

    Anyone has the solution?

    Its quite annoying to have all <p>‘s and <br />‘s striped from the content everytime you update the post.

    Hope someone find a solution for this!

    I have been struggling with this same issue all morning and have solved the issue(I hope I am not posting soon, but so far so good!). I was adding a second content area for a 2 column layout so the client could better understand where the content was going. (Yes, I know you can simply use short code to insert the end and start of new divs.)

    Please keep in mind, I use custom field methods similar to this excellent article.

    For the post edit textarea displayed value I use:

    <textarea class="theEditor" name="content_two_value" id="content_two_value"><?php echo wpautop(get_post_meta($post->ID, 'content_two_value', true)); ?></textarea>

    The key is enclosing the echoed value in wpautop().

    Be sure to also use the same wpautop() function above for your live display as well.

    Many thanks to WPsites as well for the tip on tinymce integration!

    Hope this helps someone out!

    Thread Starter ancawonka

    (@ancawonka)

    Wow, I haven’t looked at this post in a while, but came back to it. This whole thread is super-helpful! Thanks especially @racer x.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How can I use the tinyMCE editor for fields in my Custom Post Type?’ is closed to new replies.