WordPress.org

Ready to get started?Download WordPress

Forums

Wp editor get data (2 posts)

  1. wptweaking
    Member
    Posted 1 year ago #

    Dear All,
    I am currently developing a plugin.
    I got the following code from the codex

    // Update post 37
      $my_post = array();
      $my_post['ID'] = 37;
      $my_post['post_content'] = 'This is the updated content.';
    
    // Update the post into the database
      wp_update_post( $my_post );

    I would like to know how to update post content directly from wp editor instead of defining it in the code.

    I tested the following, but as result the post content was deleted and I end up with an empty post:

    // Update post
      $my_post = array();
      $my_post['ID'] = 37;
      $my_post['post_content'] = $_POST["syf_editor"];
    
    // Update the post into the database
      wp_update_post( $my_post );
     wp_editor( $content, syf_editor, $settings = array() );

    My main need is a way to get the data from wp editor.

    Thanks for any hint on this matter.

    Pietro

  2. bcworkz
    Member
    Posted 1 year ago #

    wp-editor() is essentially a fancy textarea form element. You must still provide a form tag with it's action and method attributes, and a submit button or equivalent to initiate the form submission. You then can get the content of the editor from the $_POST array with the editor's id/name as key. In your example, $_POST['syf_editor'].

    Once whatever page receives the request, it must extract the form information and process it as required, which might include inserting values in the DB.

    Also note in your example, the reason the editor was blank is you provided the content parameter as $content, which was never assigned a value. This value should come from the DB somehow, not from a $_POST element.

Topic Closed

This topic has been closed to new replies.

About this Topic