Home › Forums › ACF PRO › Dynamically restrict media modal attachments › Reply To: Dynamically restrict media modal attachments
Hi @verde
You should be able to do it by using the “pre_get_posts” hook like this:
add_action('pre_get_posts','my_acf_image_change_query');
function my_acf_image_change_query( $wp_query_obj ) {
// only do this on certain field
if( isset($_POST['query']) && $_POST['query']['_acfuploader'] == 'field_1234567890abc' ){
// get the current post ID
$post_id = $_POST['post_id'];
// get the relationship raw value
$relationship = get_field('custom_field_name', $post_id, false);
// set the parent query
$wp_query_obj->set( 'post_parent__in', $relationship );
}
}
Where “field_1234567890abc” is the field key.
I hope this helps 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.