So when I am creating a post, I would like to only be able to see images (after clicking ,add media above wp editor) that have been uploaded and attached to posts of the same family of the current post i'm creating.
My current code does not seem to work.
global $post;
$parentID = $post->post_parent; //Shows 2068
$currID = $post->ID; //Shows 2069
$args = array('post_parent' => $post->ID, 'post_type' => 'projects', 'numberposts' => -1 );
$children = get_children($args);
foreach ($children as $child):
$childIDs .= " ".$child->ID; //Get Children IDs
endforeach;
$allIDs = $parentID." ".$currID.$childIDs; //shows 2068 2069 2070 2071
add_filter( 'ajax_query_attachments_args', 'wpb_show_current_user_attachments');
function wpb_show_current_user_attachments( $query, $allIDs ) {
$allIDarray = explode (" ", $allIDs);
//$user_id = get_current_user_id();
if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts') ) {
// $query['author'] = $user_id;
$query['post_parent'] = $allIDarray;
}
return $query;
}
ajax_query_attachments_args
sends to its callbacks. And what are those code above theadd_filter()
? They should be in the callback.