Support

Account

Home Forums Front-end Issues Relationship posts private?

Solved

Relationship posts private?

    • blg002

    • January 3, 2014 at 8:56 am

    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 capability_type.

    • Elliot

    • January 3, 2014 at 10:53 am

    Hi @blg002

    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; 
    

    Thanks
    E

    • blg002

    • January 4, 2014 at 5:28 am

    so:

    $talks = get_field('conference_talks', false, false);
    print_r($talks);
    
    Array
    (
        [0] => 3997
        [1] => 3998
        [2] => 3996
        [3] => 3995
        [4] => 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.

    Update:

    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.

    • Elliot

    • January 4, 2014 at 12:05 pm

    Hi @blg002

    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?

    Good luck,

    Thanks
    E

    • blg002

    • January 5, 2014 at 3:08 am

    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.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

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.