Get all Wordpress post meta


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

Gets all of a Wordpress post meta data in an array without specifying a key


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.