This is one of those problems that I've spent way too much time on, and there is probably a VERY simple solution that I am missing. Any help would be greatly appreciated.
I am trying to populate a select box with names from custom data (
pyd_pub_author"). But, I cant just call the data directly, because it also needs to make sure that, meta_key
"pyd_pub_type" = "Newsletter"
meta_key "pyd_pub_type" needs to be
"Newsletter" and the author names needs to come from meta_key "
pyd_pub_author". The tricky part is, there are many other "
pyd_pub_authors" that are associated with other "
pyd_pub_type", I need to filter them out as well.
So, I need to filter out the meta_value "
Newsletter" and all "
pyd_pub_author" that are associated with it.
What I've done is this:
$metakey = $prefix . 'pub_author'; $authors_query = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT meta_value, post_id FROM $wpdb->postmeta WHERE meta_key = %s HAVING post_id = ANY ( SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_value = 'Newsletter' ) ", $metakey ) );
This returns the name of an author for each of the post_id(s) that match the list, even if they are duplicate. The "DISTINCT" isnt filtering the names because it is checking the post_id.
So, what this leaves me to to is run an array_unique() to strip out the duplicates. It works, but there has to be an easier, less expensive way to do this.
head->desk, head->desk, head->desk...