Home » Topics » General Support » Post Object again

Post Object again

ACF Widgets Support General Support Post Object again

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #95037
    Tomas Siroky
    Participant

    Hi, I’ve got the same issue as it’s here: https://acfwidgets.com/support/topic/post-object/. In the widget is the same title as it’s on the top of page. Doesn’t matter if that’s post or page. I need to show there post which I choose in the widget… Any solution?

    $post_object = get_field(‘my_post_object’, $acfw);

    if( $post_object ):

    // override $post
    $post = $post_object;
    setup_postdata( $post );

    ?>
    <div>
    <h3>“><?php the_title(); ?></h3>

    </div>
    <?php wp_reset_postdata(); // IMPORTANT – reset the $post object so the rest of the page works correctly ?>
    <?php endif; ?>

    #95051
    Daron Spence
    Keymaster

    I think you might need to declare the $post global since the context could be different.

    Try adding global $post; before the $post = $post_object; line.

    If that doesn’t get what you want. You can access most of the data directly on the post object itself.

    https://codex.wordpress.org/Class_Reference/WP_Post

    Something like echo $post_object->post_title; is the same as the_title() (unless you are running filters on the title).

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.