And is it possible to create some function that will do the next
When I chose some post(post 2) in a relationship in Post 1 it will automatically choose Post 1 in a relationship in Post 2?
You understand what I mean?)))))
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(); ?>
I have found(with your help) other solution.
I use acf/save_post filter, and save info to the CF from the sub-post(post_object, named Team) to the main post(named Event)
Thanks for your answer!
Can you tell me more about update_post_meta() and meta key?
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.