• Hello guys!
    I’m looking for a way to update editor content with value pulled from DB based on a select menu value.

    The base code works something like this:

    <select name="user_input">
    <option value="ID1"></option>
    <option value="ID2"></option>
    <option value="ID3"></option>
    </select>
    
    global $wpdb;
    $content = $wpdb->get_var( "SELECT content FROM $wpdb->table WHERE post_id=$user_input" );
    
    $editor_id = 'mycustomeditor';
    wp_editor( $content, $editor_id );

    I need this to happen without a page reload.
    I will greatly appreciate any help or tips.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You should be able to find a plugin that does this kind of thing, you will be able to adapt it to your needs.

    The page that the browser loads will be a custom page template of your child theme, this page will load the required javascript and also your option code.
    In the browser you will have javascript hooking the select/option control, upon each change it will instigate an AJAX call to your web server that specifies the requested page ID, the server side PHP file invoked by the AJAX request will do the SQL query to fetch the page contents, and send this back to the browser in the AJAX response. At the browser the javascript receiving this response will inject the response into the DOM.

    Here is an AJAX referance:
    https://developer.wordpress.org/plugins/javascript/ajax/

    Suggest that you search and browser plugins to find something that you can adapt.

    Moderator bcworkz

    (@bcworkz)

    I just want to make it clear that if you adapt a plugin in this manner, you would essentially fork it under a new name, except it’s not published. Don’t hack up a plugin then try to update it! You’ll lose all of your custom code.

    Ross’ summary is so succinct and accurate I would suggest you piece together your own code based on it and take examples from other plugins and code snippets as needed rather than trying to find the closest plugin to your needs. I think it’s easier to find elements that do what you want than entire plugins.

    IMHO of course, do what works best for you.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Dinamiccally pull value from database’ is closed to new replies.