Skip to content

Instantly share code, notes, and snippets.

@certainlyakey
Created March 16, 2018 10:11
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 certainlyakey/31cedf61f58b14dc1e0dbed683a56a03 to your computer and use it in GitHub Desktop.
Save certainlyakey/31cedf61f58b14dc1e0dbed683a56a03 to your computer and use it in GitHub Desktop.
Remove current post from relationship fields which refer to the same post type (Wordpress + ACF)
<?php
// Remove current post from relationship fields which refer to the same post type
function remove_current_post_from_self_relationships($args, $field, $post_id) {
$args['post__not_in'] = array($post_id);
return $args;
}
$self_relationship_fields = array('relation_cases_cases');
foreach ($self_relationship_fields as $key => $field_name) {
add_filter('acf/fields/relationship/query/name=' . $field_name, 'remove_current_post_from_self_relationships', 10, 3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment