Created
August 15, 2015 10:32
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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