Home Forums General Issues Get Page ID array from Post Object


Get Page ID array from Post Object

  • I have a post object field that allows multiple pages, and I want to get an array of all page IDs that are selected. I have tried a couple ways, however it’s not outputting the correct page IDs.

    <?php $exclusions = get_field('exclusions'); if( $exclusions ) {
    foreach($exclusions as $exclusions) { echo $exclusions->ID; }
    } ?>

    I’ve also used echo get_the_ID($exclusions->ID) with the above with no luck. And:

    <?php $exclusions = get_field('exclusions'); if( $exclusions ) {
    foreach( $exclusions as $post) { setup_postdata($post); echo $post->ID; } wp_reset_postdata();
    } ?>

    Thanks for the help.


  • Hi @klayemore

    Your code should be working just fine.

    Kindly do a var_dump of the $exclusions and let me know what is returned.

    Hope to hear from you soon.

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

The topic ‘Get Page ID array from Post Object’ is closed to new replies.