Home Forums ACF PRO Using Relationship Fields with Sensei plugin


Using Relationship Fields with Sensei plugin

  • I am total novice in PHP and trying to get the Sensei lesson data to display on my pages using the relationship fields.

    I can see the Woothemes Sensei lesson data on the relationship data field on the backend, but I am not sure what is the correct way to fetch the data to my frontend page.

    I have added the following code on my page. Should I use a custom post type name ($lessons) instead to get the data, or what am I doing wrong?

    $posts = get_field('related_lessons');
    if( $posts ): ?>
        <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
            <?php setup_postdata($post); ?>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                <span>Custom field from $post: <?php the_field('author'); ?></span>
        <?php endforeach; ?>
        <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>
  • If you have a custom field name ‘related_lessons’ and it is a relationship field that selects posts in a custom post type then what you’re doing should be working.

    Does this output the permalink and the title of the lesson post?
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>

    What kind of field is ‘author’ on the lesson post type?

  • Thanks.

    I got it to work now. I think it was just something with the marking.

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

The topic ‘Using Relationship Fields with Sensei plugin’ is closed to new replies.