Skip to content

Instantly share code, notes, and snippets.

@craigsimps
Created August 15, 2015 10:32
Show Gist options
  • Save craigsimps/9c4c767f66ae5a85e6e3 to your computer and use it in GitHub Desktop.
Save craigsimps/9c4c767f66ae5a85e6e3 to your computer and use it in GitHub Desktop.
By default, get_field will often return an array of post objects. If you try to access this using get_post_meta, you will see only an array of post ids. This function allows you to input the field name, and returns an array of post objects.
<?php
function return_array_of_objects_from_acf_ids( $field_name ) {
$post_ids = get_post_meta( get_the_ID(), $field_name, true );
foreach ( $post_ids as $post_id ) {
$objects[] = get_post( $post_id );
}
return $objects;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment