Filter by multiple custom fields in the loop
-
Hi,
Does anyone know how to filter the loop using multiple custom fields? below is the code I’m currently using to filter by one custom field:
function filter_join($join) { global $wpdb; $join .= " JOIN wp_postmeta ON " . $wpdb->posts . ".ID = wp_postmeta.post_id "; return $join; } add_filter('posts_join', 'filter_join'); function filter_where($where) { $where .= " AND (wp_postmeta.meta_key = 'gender' AND wp_postmeta.meta_value = 'male') "; return $where; } add_filter('posts_where', 'filter_where'); query_posts($query_string);
I’ve tried adding the others by just using an AND, but this doesn’t work, I assume because this will be joining only to on row in the wp_postmeta table.
Thanks!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Filter by multiple custom fields in the loop’ is closed to new replies.