Created
June 9, 2018 07:22
-
-
Save DimaMinka/71b2e2d342c6bcae8c7fe089dbff38e6 to your computer and use it in GitHub Desktop.
Get child pages relationship - Carbon Fields
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
/** | |
* Child pages filter | |
* | |
*/ | |
function cdk_child_carbon_relationship_options( $options, $field_name ) { | |
if ($field_name == '_featured_articles') { | |
$parent_id = $_GET['post']; | |
$args = array( | |
'post_type' => 'page', | |
'numberposts' => -1, | |
'post_parent__in' => array($parent_id) | |
); | |
$posts = get_posts($args); | |
$post_ids = []; | |
if ($posts) | |
foreach ($posts as $post) | |
{ | |
$post_ids[] = $post->ID; | |
} | |
foreach($options as $index => $page) { | |
if (!in_array($page['id'], $post_ids)) { | |
unset($options[$index]); | |
} | |
} | |
} | |
return $options; | |
} | |
add_filter('carbon_relationship_options', 'cdk_child_carbon_relationship_options', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment