Wordpress | Get All Meta Data


/ Published in: PHP
Save to your folder(s)

Gets all meta data keys/values for a particular post


Copy this code and paste it in your HTML
  1. function get_post_meta_all($post_id){
  2. global $wpdb;
  3.  
  4. $data = array();
  5.  
  6. $wpdb->query("
  7. SELECT `meta_key`, `meta_value`
  8. FROM $wpdb->postmeta
  9. WHERE `post_id` = $post_id
  10. ");
  11.  
  12. foreach($wpdb->last_result as $k => $v){
  13. $data[$v->meta_key] = $v->meta_value;
  14. };
  15.  
  16. return $data;
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.