Here's the TLDR: Is is possible to get all meta keys from a specific CPT without a database hit for each post?
If so, how can I do this the Wordpress way?
This seems like a simple thing to do ( at least from a database perspective ) but I'm looking for the Wordpress way to get multiple post_meta values from a bunch of CPTs. Example:
Every Product
Custom Post Type has the following fields ( plus many more ) which holds discrete pieces of information:
_ns_research_document
_ns_monograph_document
_ns_profile_document
Essentially, I want a list of ALL Research Docs, Monographs and Profile Docs. Currently this site has 72 product
posts, but other sites this will be used on have over a thousand.
I assume there's a way to do this with wordpress methods that doesn't involve [at least] 73 calls ( one for all posts, and then get_post_meta
inside the loop ).
The general solution I've found suggest a get_post_meta inside a foreach loop: https://stackoverflow.com/questions/14699686/custom-post-type-loop-only-displays-first-post-meta-data
But in this case, I really only want the meta_values
in an array for a specific CPT.
Database Logic tells me that this should be only 2 queries... one on the post_meta table, one on the the posts table. It might include some joins, but still a rather inexpensive couple of queries.