Skip to content

Instantly share code, notes, and snippets.

@paulmist
Created February 18, 2015 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulmist/50419d98643a52c8a65d to your computer and use it in GitHub Desktop.
Save paulmist/50419d98643a52c8a65d to your computer and use it in GitHub Desktop.
ACF - Dynamically populate selected entries in Relationship field
add_filter('acf/load_value/name=name-of-relationship-field', function($value) {
if(empty($value)) {
$value = get_posts(array(
'post_type' => 'name-of-post-type',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'fields' => 'ids',
));
}
return $value;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment