Okay, so long story short… there’s no built-in wordpress way to Query the meta-data directly, but in the interests of helping others, essentially you need to do it the old-fashioned way… using SQL:
I’m going to do up a post which I’ll link to… but essentially it involves straight SQL and $wpdb->get_results
and some PHP loops.
To get all the values for _ns_research_document
, _ns_monograph_document
, and _ns_profile_document
I did this:
// prepare SQL
$wpdb->prepare("SELECT DISTINCT post_id, meta_key, meta_value"
." FROM " $wpdb->postmeta
." WHERE meta_key IN ( '_ns_research_document', '_ns_monograph_document', '_ns_profile_document') "
." ORDER BY post_id, meta_key ASC" );
// call DB
$results = $wpdb->get_results( $sql );
It returns an array with an array for each row, which I was able to loop through and recategorize. Kind of surprising I couldn’t find a WP way to do this without SQL, but such is life.
Note that if you wanted to be sure to ONLY get product
posts, you’d probably have to do an INNER JOIN in your sql.