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?
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!
© 2019 Advanced Custom Fields. Subscribe