Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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;
}
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
add comment

Your Answer

 
discard

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.