Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The answer was from <a href="https://wordpress.stackexchange.com/a/59968/18428">the same question I asked somewhere else</a></p> <p>And I created my version of example</p> <p>I added some console.log function for testing, but this is basically doning the same thing as @Chris_() answer:</p> <p>Menu callback function to generate menu content (PHP):</p> <pre><code>function ajax_menu_callback() { ?&gt; &lt;div class="wrap"&gt; &lt;div id="icon-themes" class="icon32"&gt;&lt;/div&gt; &lt;h2&gt;Test&lt;/h2&gt; &lt;br /&gt; &lt;form&gt; &lt;input id="meta" type ="text" name="1" value="&lt;?php echo esc_html( get_post_meta( 1, 'your_key', true) ); ?&gt;" /&gt; &lt;?php submit_button(); ?&gt; &lt;/form&gt; &lt;/div&gt; &lt;?php } </code></pre> <p>Then the javascript to print on the admin side (javascript, don't forget to include a jquery library):</p> <pre><code>jQuery(document).ready(function() { $("form").submit(function() { console.log('Submit Function'); var postMeta = $('input[name="1"]').val(); console.log(postMeta); var postID = 1; var button = $('input[type="submit"]'); button.val('saving......'); $.ajax({ data: {action: "update_meta", post_id: postID, post_meta: postMeta, }, type: 'POST', url: ajaxurl, success: function( response ) { console.log('Well Done and got this from sever: ' + response); } }); // end of ajax() return false; }); // end of document.ready }); // end of form.submit </code></pre> <p>Then the PHP function handle update_post_meta (PHP):</p> <pre><code>add_action( 'wp_ajax_update_meta', 'my_ajax_callback' ); function my_ajax_callback() { $post_id = $_POST['post_id']; $post_meta = $_POST['post_meta']; update_post_meta( $post_id, 'your_key', $post_meta ); echo 'Meta Updated'; die(); } // end of my_ajax_callback() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload