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?

2 Answers 2


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.


Use get_post_custom_keys():

$fields = get_post_custom_keys( get_the_ID() );
  • 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
    Commented May 25, 2013 at 19:34
  • No, this works only for a given post ID.
    – fuxia
    Commented May 25, 2013 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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