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 am using a theme which has defined a custom post type--

Now, I am trying to retrieve the list of metadata fields used by that post type-- so that I can insert data via PHP code in form of that custom post--I just want the list of meta data fields(not the values of metadata fields for specific posts-- but the list of metadata fields for that type of custom post).

How do I do this?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

I assume that you are talking about post meta-- data stored in the $wpdb->postmeta table when you talk about "meta data fields". The data in that table is associated with particular posts, of whatever type. It is not in any way keyed directly to the post type itself. There would be no way to connect a meta data field with a post type except by JOINing on the $wpdb->posts table based on the post ID and checking the post_type for that post ID.

You can't have meta data associated with a post type without having posts in that post type.

The only way I could see around that is if your theme has hard-coded post type meta data or stores that date somewhere else-- the $wpdb->options table perhaps-- or if maybe the meta data keys are in some way identifiable by name-- say books_cpt_author for a books post type. If that is the case, how you would get that information depends on how the theme has created/stored the data, and your question doesn't contain enough information to guess at that.

share|improve this answer

Use get_post_custom_keys():

$fields = get_post_custom_keys( get_the_ID() );
share|improve this answer
    
will this work even when no post has yet been made on the custom post type-- this is a new template i have just purchased... thanks –  Arvind May 25 '13 at 19:34
    
No, this works only for a given post ID. –  toscho May 25 '13 at 19:34

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.