Support

Account

Home Forums Gutenberg Gutenberg Relationship field, can't get title from another block

Helping

Gutenberg Relationship field, can't get title from another block

  • So, I’ve got a relationship custom field made with a Gutenberg blocks, pulling in posts that were also made with Gutenberg.

    So, I’m having issues trying to get my Guternberg title to show up in my relatioship loop. Because everything is in groups, I’m not sure how to get accress to the custom title

        <div class="container-project">
                <h2><?php echo get_field('recent_projects')['title']?></h2>
         
            <?php $projects = get_field('recent_projects')['recent_project']?>
            <?php if($projects) {?>
    
                <?php foreach($projects as $post) {?>
                    <?php setup_postdata($post); ?>
            <div class="project-index project-index--featured project-index--top-right flexing">
            <a href="<?php echo the_permalink($post)?>">
                    <picture class="project-index__image">
                <img  src="<?php echo get_the_post_thumbnail($post)?>">
            </picture>
        <div class="project-index__content">
    *************** Problem here *****************
            <p class="project-subject"><?php echo the_field('top_post_content')['title']?></p>
    *************************************************************
            <p class="project-subject"><?php  echo get_the_title($post)?></p>
            <button class="arrow-link">
            <svg role="img" class="svg-arrow">
            <use xlink:href="../assets/svg/svg-sprite.svg"></use>
    </svg></button>
        </div>
    </a>
            </div>
            <?php wp_reset_postdata(); ?>
    
            <?php } ?>
    
            <?php } ?>
    
    </div>
    
  • In the problem line:

    <?php
    <p class="project-subject"><?php echo the_field('top_post_content')['title']?></p>

    you may want to replace the_field with get_field, or omit echo.

    I take it, top_post_content refers to a post. In the back-end you can pick if you want the field to return a post object or merely the post ID, in which case it will not return the title. You could use:

    <?php
    get_the_title( get_field('top_post_content') )
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Gutenberg Relationship field, can't get title from another block’ is closed to new replies.