0

I have reviewed this question, however I don't think that's good enough for what I want to do.

I'm developing a plugin that needs to be aware of different fields available on custom post types, so I want to be able to retrieve that list for a given type. I don't want to have to hard code in a specific Post ID, because what if the type exists yet there are no posts available? Is this even a realistic concern?

What the answer to that question advocates is to get a post of the custom post type first, then get the custom fields with:

get_post_custom($post_id)

Is it not possible to just query wpdb somehow in order to generate this list, rather than find a post and then call get_post_custom? I am retrieving the list of post types via get_post_types()

Update

What I'm using this for is integrating a search service provider, and I want to let an Admin user decide which specific fields of each post type to include in the search index. If a new post type is added with custom fields and before any new posts of this type have been added the admin visits my settings page, I believe there will be issues. Besides, conceptually, I don't feel I should have to reference a specific post in order to get information about it's type (it could be that Wordpress itself disagrees, however).

  • if you have no posts, then there can't be any post meta fields. – Milo Nov 12 '15 at 15:26
  • Sounds like an incredibly specific use case. You may receive some helpful input if you can briefly describe your challenge. There are likely alternative approaches to be suggested. – jdm2112 Nov 12 '15 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.