Home › Forums › General Issues › Relationship Object Not Showing
Hello,
I created a custom post type (Events) and I created another custom post type (Instructors), which I classified the instructors post type as a relationship custom field in ACF. I am populating the Event Post Type list just fine, however when I try to call the Instructor custom field, it either wont show up or it will kill the string of events and just show one. Don’t know what I am doing wrong. Thanks in advance for any help you guys can provide. π
<?php
/**
* Template Name: Classes
*
*/
get_header(); ?>
<div class="container">
<?php
$today = date('Ymd');
$instructor = get_field('instructors');
// get posts
$posts = get_posts(array(
'post_type' => 'event',
'posts_per_page' => -1,
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'compare' => '>',
'value' => $today,
'type' => 'DATE',
'meta_query' => array(
array(
'key' => 'instructors',
'value' => $instructor,
'compare' =>'IN',
),)
),)
));
if( $posts ): ?>
<?php foreach( $posts as $post ):
setup_postdata( $post )
?>
<a class"class"href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a>
<img style="float: right; max-width: 28%;"src="<?php the_field('event_image'); ?>"/><h3>Event Date :
<?php the_field('event_date'); ?>
</h3>
<h4>Start Time: <?php the_field('start_time'); ?></h4>
<h4>End Time: <?php the_field('end_time'); ?></h4>
<p><?php the_field('description'); ?></p>
<?php if($instructor): ?>
<?php the_field('instructors'); ?>
<?php endif; ?>
<?php echo do_shortcode('[addtoany]'); ?>
<div class="clear"></div>
<hr>
<?php endforeach; ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
<div class="clear"></div>
</div>
<?php get_footer(); ?>
Your meta_query is a bit off I think, the second meta_query is overriding the second.
$posts = get_posts(
array(
'post_type' => 'event',
'posts_per_page' => -1,
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'compare' => '>',
'value' => $today,
'type' => 'DATE',
),
array(
'key' => 'instructors',
'value' => $instructor,
'compare' =>'IN',
),
)
),
);
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βre excited to announce we've released Composer support for installing ACF PRO.
— Advanced Custom Fields (@wp_acf) January 31, 2023
π #ComposerPHP fans rejoice!
β¨ Please see the release post for all the details and full instructions. https://t.co/ebEfp61nlR
© 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.