Home Forums Front-end Issues get_fields on a custom post type archive page


get_fields on a custom post type archive page

  • I have a custom post type called semesters. I created an archive page for that post type called archive-semesters.php. On the template page of archive-semesters.php, I’m trying to get all the fields of each post but when I call the get_fields function it’s returning null.

                  while ( have_posts() ):
                    $title = get_the_title();
                    $post_id = get_the_id();
                    $fields = get_fields( $post_id );
                          echo '<pre>';
                            var_dump( $post_id );
                            var_dump( $fields );
                          echo '</pre>';
    • vverner

    • October 3, 2019 at 5:52 am

    Hey man,

    Inside the loop you don’t need to pass the post id argument. Try if just $xxx = get_fields();

    And remeber, ” get_fields() ” will only return fields that have value on the post

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.