The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] How to insert data into post area? (4 posts)

  1. Canha
    Posted 5 years ago #

    Hey guys, I have a question.

    I'm creating a plugin that shows a custom box in a custom post type area. When the user inserts data into an input inside this custom box, the plugin uses this value to return another one.

    How can I automatically copy this input into the post area? (Where the post is written). I've considered just telling the user to CTRL+C, CTRL+V in the post area. But there has to be another way. I thought of Javascript, but I want to know if there is any other way to do this.


  2. juliovedovatto
    Posted 5 years ago #

    Try this (javascript):

    window.send_to_editor('VALUE THAT U WANT');
    window.location.hash = 'postdivrich';

    I respond to you here, because in twitter you never see what I send to you LOL

  3. Canha
    Posted 5 years ago #

    Thanks! Sorry, didn't see you reply on Twitter (keep getting lots of those).

    I ended up using javascript in a different way, as I couldn't find a non-JS solution:
    document.getElementById("content").value = "<?php echo $myVar; ?>";

    as #content is the ID for the textarea.

    I'm leaving this here for anyone who might have this trouble:
    It's easier to use Javascript (or jQuery) to insert data into the post textarea. If you must insert the data without cleaning up the textarea, do the following:

    var whatIsAlreadyThere = document.getElementById("content").value;
    var whatYouWantToAdd = "Whatever you want to add";
    document.getElementById("content").value = whatIsAlreadyThere + whatYouWantToAdd

    You may want to add some kind of space in the second var.

  4. Leo Blanchette
    Posted 5 years ago #


    two months later...had to express thanks! You solved my problem in two lines of code. Thanks a lot!!!!!!!

    Original thread...


Topic Closed

This topic has been closed to new replies.

About this Topic