Home › Forums › Front-end Issues › ACF Search in Post Object › Reply To: ACF Search in Post Object
I have been changed post_object to the Relationship and have one problem.
When I load category all information load good, but when I trying to search I have disappeared one field (the second field send me empty array ). Where is have a mistake?
Function for filter
<?php
function go_filter()
{
$_name = $_GET['tournament_name'] != '' ? $_GET['tournament_name'] : '';
$args = array(
'post_type' => 'events', // your CPT
's' => $_name
);
$args['meta_query'] = array('relation' => 'AND');
global $wp_query;
if ($_GET['team_1'] != '') {
$args['meta_query'][] = array(
'key' => 'filter_team_1',
'value' => $_GET['team_1'],
);
}
if ($_GET['team_2'] != '') {
$args['meta_query'][] = array(
'key' => 'filter_team_2',
'value' => $_GET['team_2'],
);
}
query_posts(array_merge($args, $wp_query->query));
}
?>
And page content
<?php if ($_GET && !empty($_GET)) {
go_filter();
} ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $team_1 = get_field('team_1'); ?>
<?php $team_2 = get_field('team_2'); ?>
<li>
<div class="team">
<?php echo get_the_post_thumbnail($team_1[0]); ?>
<?php echo get_the_title($team_1[0]); ?>
</div>
<div class="separate">VS</div>
<div class="team">
<?php echo get_the_post_thumbnail($team_2[0]); ?>
<?php echo get_the_title($team_2[0]); ?>
</div>
<div class="time"><?php the_field('game_time'); ?></div>
<a href="<?php the_field('game_link'); ?>">Tournament</a>
</li>
<?php endwhile;
else : ; ?>
<h4>Sorry, nothing matched your search criteria!</h4>
<?php endif; ?>
<?php wp_reset_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 demoed ACF 6.1 Beta during the most recent session of ACF Chat Fridays, highlighting the new ability to regenerate and clear labels, setting the Admin Menu Parent as a slug, and more. Catch the video replay in our latest summary. https://t.co/rHEpPVas64 pic.twitter.com/hB1XKTexXi
— Advanced Custom Fields (@wp_acf) March 23, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.