Home Forums Front-end Issues Page broken when using Post Object


Page broken when using Post Object

  • Something weird is going with my page: I want to implement “Read next page”-buttons at the bottom of each page using acf. When I use Page Link (outside the loop), everything is working fine.

    But as I need more options, I tried Post Object. Links/link titles display fine, but the rest of the page gets chopped off/is broken.

    Here’s the code I use:

      $post_object = get_field('previous_page');
      if( $post_object ): 
        // override $post
        $post = $post_object;
        setup_postdata( $post );
    <a class="previous-page" href="<?php the_permalink(); ?>"><i class="fa fa-chevron-left"></i> LRead more about <?php the_title(); ?></a>
    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>

    Any idea what could be the reason for this?

    Thanks, George

  • According to the codex what you have should be working. The only reason I can think that it isn’t is that if $post_object does not hold a post object in the way that WP is expecting.

    If the page is broken, as in nothing is being displayed, then there is some kind of fatal error happening. You could put the following into your config.php file and see if you can see what the error is.

    define( 'WP_DEBUG', true );
    define( 'WP_DEBUG_DISPLAY', true );
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Page broken when using Post Object’ is closed to new replies.