I'm looking for a way to only show posts results that contain all of the custom fields requested. Not one or the other. I was only able to get results with one array at a time. Any help would be appreciated.
$documents = array(
'post_type' => 'documents',
'meta_query' => array(
array(
'key' => 'document-type',
'value' => 'manual',
),
array(
'key' => 'document-status',
'value' => 'current',
)
)
);
query_posts( $documents );
get_template_part( 'loop', 'documents' );
wp_reset_query();
I also tried an SQL Query without any luck.
$documents = "
SELECT wposts.*
FROM $wpdb->posts wposts
JOIN $wpdb->postmeta document-status ON
( wposts.ID = document-status.post_id AND
document-status.meta_key = 'document-status' )
JOIN $wpdb->postmeta document-type ON
( wposts.ID = document-type.post_id AND
document-type.meta_key = 'document-type' )
WHERE document-status.meta_value = 'current'
AND document-type.meta_value = 'manual'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'documents'
AND wposts.post_date < NOW()
ORDER BY wposts.post_date DESC
LIMIT 0 , 4
";
$documents = $wpdb->get_results($documents, OBJECT);
query_posts( $documents );
get_template_part( 'loop', 'documents' );
wp_reset_query();