Home › Forums › General Issues › Getting merged results › Reply To: Getting merged results
Progress.
With this code in functions.php I can get the AND posts; that is, posts tagged with “Toronto” AND posts that have “Toronto” assigned to the meta_city field.
I need the “OR” of course. Still searching. All feedback is welcome.
add_action( 'pre_get_posts', 'md_modify_tag_archive_to_include_acf_fields' );
function md_modify_tag_archive_to_include_acf_fields( $query ) {
if( $query->is_main_query() && $query->is_tag ) {
$term_name = $query->query[tag];
$term = get_term_by('name',$term_name, 'post_tag');
$meta_query = array(
'relation' => 'OR',
array(
'key' => 'meta_city', // name of custom field
'value' => $term->term_id,
'compare' => 'LIKE'
)
);
$query->set( 'meta_query', $meta_query);
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.