The current WP_Post object is passed as the second parameter. When you add your callback, specify 2 as the fourth arg.
add_filter('attachment_fields_to_edit', 'my_callback', 10, 2);
Collect the two parameters in your function declaration.
function my_callback( $fields, $post ) {
// do something with $fields based on $post value
return $fields;
}
Thread Starter
zaqwer
(@zaqwer)
In
function my_callback( $fields, $post ) {
// do something with $fields based on $post value
return $fields;
}
$post is attachment post_type, I need to acces my custom post_type where I want to modify window for adding media.
-
This reply was modified 4 years, 6 months ago by
zaqwer.
If the attachment belongs to your CPT, the CPT ID will be in $post->parent. You can then use get_post() to get your post object.
If not, maybe the ID can be determined from something else like $_GET['post'] or maybe in $GLOBALS somewhere.