WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to find all the meta keys or meta boxes preferably from just a post type ...couldn't find any wordpress function to do this. Any custom queries?

share|improve this question

get_post_custom will return all the meta_key => meta_value pairs for a given post. It returns the fields in sort of a weird format, however.


$meta = get_post_custom(1);

$meta would be...

   'some_meta_key' => array(

Unless you mean get all meta for all posts in a given post type, for that you'll need a custom query.

function wpse65225_get_all_meta($type)
    global $wpdb;

    $res = $wpdb->get_results($wpdb->prepare(
        "SELECT post_id, meta_key, meta_value FROM {$wpdb->postmeta} WHERE post_id IN
        (SELECT ID FROM {$wpdb->posts} WHERE post_type = %s)", $type
    ), ARRAY_A);

    return $res;
share|improve this answer
Hey thanks for replying...What I have is a meta box set for a particular custom post type...So I just wanted to grab the meta field keys that custom post type supports..I don't need to work with post ids...just the post type.. Any ideas? – Poulomi Nag Sep 16 '12 at 12:28
post types can support any meta keys. The metadata api doesn't restrict anything like that. There are meta keys that the core uses, but they aren't really documented. – chrisguitarguy Sep 16 '12 at 14:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.