Support

Account

Home Forums General Issues Get Page ID array from Post Object

Helping

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.

    Cheers,
    Klaye

  • 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)

You must be logged in to reply to this topic.