Home › Forums › General Issues › Querying relationship with True / False
Hi,
I have a post type called rto_providers which has a relationship field to select which courses they provide from another post type called courses. A list of providers will be showing on specific course pages according to the relationship selection. In case if I want to deactivate a specific provider I thought of using True/False function on rto_providers so that provider will be temporary removed from the list.
I tried following code. But I’m getting all the providers which has a true value.
<?php while ( have_posts() ) : the_post();
$rto_providers = get_posts(array(
'post_type' => 'rto_providers',
'meta_query' => array(
array(
'key' => 'courses_offered',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE',
'key' => 'status',
'compare' => '==',
'value' => '1'
)
)
));
?>
<?php if( $rto_providers ): ?>
<?php foreach( $rto_providers as $rto_provider ): ?>
<div class="row bordered-row random">
<div class="col-md-2 providers-list">
<?php echo get_the_post_thumbnail( $rto_provider->ID ); ?>
</div>
<div class="col-md-8">
<a href="<?php echo get_permalink( $rto_provider->ID ); ?>">
<?php echo get_the_title( $rto_provider->ID ); ?>
</a>
</div>
<div class="col-md-2">
<a href="<?php echo get_permalink( $rto_provider->ID ); ?>" class="btn btn-base">
Visit Page
</a>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
<?php endwhile; ?>
......
'meta_query' => array(
array(
'key' => 'courses_offered',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE',
// added the next 2 lines
),
array(
// what does this represent
// those that are active or inactive
// if you toggle the field on to make it inactive
// then the value here should be 0
'key' => 'status',
'compare' => '==',
'value' => '1'
)
)
Hi John,
This is a bit hard to explain. However, I wanted to display all the course providers who has a true value(1) within the relationship. Instead I got all the course providers who has a true value(1) within and apart from the relationship. Sorted this out with a radio field by following code. (should be possible with TRUE/FALSE as well)
<?php while ( have_posts() ) : the_post();
$rto_providers = get_posts(array(
'post_type' => 'rto_providers',
'meta_query' => array(
array(
'key' => 'courses_offered',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
));
?>
<?php if( $rto_providers ): ?>
<?php foreach( $rto_providers as $rto_provider ): ?>
<?php if( get_field('account_activation', $rto_provider->ID) == 'Active' ): ?>
<div class="row bordered-row random">
<div class="col-md-2 providers-list">
<?php echo get_the_post_thumbnail( $rto_provider->ID ); ?>
</div>
<div class="col-md-8">
<a href="<?php echo get_permalink( $rto_provider->ID ); ?>">
<?php echo get_the_title( $rto_provider->ID ); ?>
</a>
</div>
<div class="col-md-2">
<a href="<?php echo get_permalink( $rto_provider->ID ); ?>" class="btn btn-base">
Visit Page
</a>
</div>
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php endwhile; ?>
You must be logged in to reply to this topic.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.