Support

Account

Home Forums ACF PRO Post Object variable is empty but not on edit page

Helping

Post Object variable is empty but not on edit page

  • I have an issue where I’m trying to pull in related posts from a CPT onto a post single page using the post object field, but I can’t get it to show on the front end. I’ve boiled the troubleshooting down to just testing if the variable is empty:

    <?php $relatedProject = get_field('pl_related_projects');
    	if ( ! empty( $relatedProject ) ) : ?>
    		<p>Not Empty</p>
    	<?php else : ?>
    		<p>Empty</p>
    	<?php endif; ?>

    …and it returns as “Empty”. But, in the post edit page. The field is filled out with a selected CPT.

    https://paste.pics/78b3d95a379f319fbd2d3999fc6e501b

    https://paste.pics/8d76347048335f6bea2f0664cd280995

    I’ve confirmed and reconfirmed the correct field is showing in the post edit page. I selected different CPTs, multiple CPTs and updated the post. But it still shows as an empty variable.

    Does anyone have ideas on what I am doing wrong?

    Running
    WP 5.8.1
    ACF Pro 5.10.2

  • Skip this question…I found my issue. I didn’t realize in another portion of the template there was a different WP Query. The variable was pulling from the wrong content.

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

You must be logged in to reply to this topic.