1

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?

1

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.

eg.

<?php
$meta = get_post_custom(1);

/*
$meta would be...

arrary(
   'some_meta_key' => array(
       'one_meta_value'
   )
);
*/

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

<?php
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;
}
2
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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