Home Forums General Issues Retrieve nested Post ID


Retrieve nested Post ID

  • I’m having some difficulty in retrieving an ID from a post object. Here is the setup:

    I have two different post-types: Jobs and Locations. On the jobs post type, I reference a location using the post-object form field.

    What I want to be able to do on the locations page is show job listings that are at that location and that is where I run into trouble…I can’t seem to retrieve the location ID referenced in the job posting so that I can compare it to the current location post that is being output.

    Here is my code thus far:

    $job_posts = get_posts( array( 'post_type' => 'job_posting', 'posts_per_page' => -1, 'order'=> 'ASC', 'orderby' => 'title' ) );
    foreach ( $job_posts as $job_post ) {
     $job_ID = $job_post->ID;
     $job_title = get_field("job_title",$job_ID);
     $job_location = get_field_object('location',$job_ID);

    This returns an array for the $job_location variable. But try as I might, I cannot access the Location Post ID which is shown here:

    ...'value' => 
         'ID' => 191,...

    Any ideas? Thanks!

  • Sheesh…just figured it out:

    $job_location_ID = $job_post->location;

    will give me the Location ID so that I can make a comparison.

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

The topic ‘Retrieve nested Post ID’ is closed to new replies.