Created
March 16, 2018 10:11
-
-
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)
This file contains hidden or 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 | |
// 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