Home Forums General Issues Displaying post_object content within shortcode Reply To: Displaying post_object content within shortcode

  • You are using this inside of a function (shortcode)

    The main thing that you’re missing is a reference $post that you need to add at the top in order to use the standard post loop

    global $post;

    However, I would not do this because when using a shortcode you can never know how deeply nested the custom queries are and wp_reset_postdata() will fail if your loop is nested inside an already existing secondary query loop.

    Instead of using have_posts() and I would not add the global reference above, I would do the following to avoid the potential problems

    if (count($output->posts)) {
      foreach ($output->posts as $post) {
        $brand = get_field('brand', $post->ID);

    So basically only use function that allow you to use the post ID rather than the normal posts loop.