[wp-trac] [WordPress Trac] #32605: Add short-circuit filters to `*_metadata_by_mid()` functions

WordPress Trac noreply at wordpress.org
Fri Jul 31 18:57:46 UTC 2015


#32605: Add short-circuit filters to `*_metadata_by_mid()` functions
-----------------------------------------+------------------------------
 Reporter:  dlh                          |       Owner:
     Type:  enhancement                  |      Status:  new
 Priority:  normal                       |   Milestone:  Awaiting Review
Component:  Options, Meta APIs           |     Version:
 Severity:  normal                       |  Resolution:
 Keywords:  has-patch reporter-feedback  |     Focuses:
-----------------------------------------+------------------------------

Comment (by Er_eri):

 Replying to [comment:4 sc0ttkclark]:
 > @Er_eri you'll want to just use `update_metadata_by_mid( 'post', absint(
 $_POST['post_id'] ), 'my_meta_key', sanitize_text_field(
 $_POST['my_meta_key'] ) );` instead here, it's already there for you to
 use it.
 >
 > https://core.trac.wordpress.org/browser/trunk/src/wp-
 includes/meta.php#L596
 >
 > You don't need new functions for `update_post_meta_by_mid` etc, this is
 definitely an edge case.


 Thank you for your reply. I'm not so good at coding. I'm trying to make it
 work but without success.

 Here is the simplest one. Is this the right one?


 {{{
 add_action( 'wp_ajax_my_action', 'isave_meta' );
 function isave_meta( $post_id ) {

 update_metadata_by_mid( 'post', absint( $_POST['post'] ), 'my_meta_key');
 }
 }}}

 And the JS:


 {{{
                 var data = {
                         action:         'my_action',
                         post_id:         $('#post_ID').val(),
                         my_meta_key:     $('#the_value').val(),

                 };
                 $.post(ajaxurl, data, function(response) {
                 alert('Got this from the server: ' + response);
                 });
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32605#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list