• Resolved fromb

    (@fromb)


    Hello,

    In stead of looping over all post type archive fields using get_field() inside while(have_archive()): the_archive();, is there a way to just get the entire object containing all fields using get_fields()?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    The generated Post Type Archive post id can be used in any ACF function or logic that is compatible with a $post_id argument. This includes:

    For example, if your Post Type Archive post id is my-post-type_archive, then you can use it like that:

    $get_field  = get_field('my_field', 'my-post-type_archive');
    $get_fields = get_fields('my-post-type_archive');
    $have_rows  = have_rows('my-post-type_archive');
    

    If you prefer to use have_archive(): the_archive(), then get_fields() will work out of the box, just like get_field(). Usage example:

    if(have_archive()):
        while(have_archive()): the_archive();
        
            // get all fields from the archive
            $get_fields = get_fields();
        
        endwhile;
    endif;
    

    You’ll find more information about the generated Post Type Archive post id and how to loop over values in the documentation here.

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter fromb

    (@fromb)

    Thanks, all good now. I’m using Timber and a CPT called ‘exhibitions’ so I had to do:

    $context['exhibitions_archive'] = get_fields('exhibitions_archive');

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    I’m glad to hear it now works as expected ??

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘post type archive: single object’ is closed to new replies.