Home › Forums › Front-end Issues › Relationship posts private?
I have a relationship field on a custom post type (Conferences) that is pulling from another custom post type (Talks), it is return the “Posts object”. The issue I’m having is that the talks only seem to appear when I log in.
The gist of the code looks like this (all I’m seeing is “Talks the coming soon”):
<?php query_posts('post_type=conference'); ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <h2><?php the_title(); ?></h2> <?php $talks = get_field('conference_talks'); ?> <?php if ( $talks ) : ?> <ul> <?php foreach( $talks as $post): ?> <li><?php the_title(); ?></li> <?php endforeach; ?> <?php wp_reset_postdata(); ?> </ul> <?php else : ?> <p>Talks coming soon</p> <?php endif; ?> <?php endwhile; endif; ?>
I am using the Members plugin for another custom post type if that means anything. Both post types have the default
It is possible that the members plugin is preventing the get_posts lookup from working correctly.
Can you try debuggin the issue by loading the un-formatted version like so:
$talks = get_field('conference_talks', false, false); echo '<pre>'; print_r( $talks ); echo '</pre>'; die;
$talks = get_field('conference_talks', false, false); print_r($talks); Array (  => 3997  => 3998  => 3996  => 3995  => 3994 )
as opposed to:
$talks = get_field('conference_talks'); print_r($talks); Array ( )
so it at least returns something, but it has appeared to caused some of the other custom fields to return incorrect values.
I guess the other fields were messed up because it was no longer return the post object and instead the post ID (aside: I’m guessing this is similar to changing the Return Format from Post Objects to Post IDs) so where before I had things like:
$user = get_field('talk_speaker'); the_field('talk_description');
I now need:
$user = get_field('talk_speaker', $post); the_field('talk_description', $post);
which I have done and seems to have everything working.
It looks like the members plugin is preventing ACF from loading the post via either get_post or get_posts functions.
Your best bet is to research the members plugin and read about it’s conflicting issues on these 2 functions.
Perhaps there is a way to temporarily disable the members ‘post protection’ before you load the ACF field value?
Thanks for your help @elliot! I think for now I’ll just stick with using
get_field('conference_talks', false, false); as it has everything working. Maybe look into the members stuff when I have some free time.
The topic ‘Relationship posts private?’ is closed to new replies.
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!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.