Use the below example code in your theme’s functions.php file to Limit upload by file type only for certain custom post type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function wpse_59621_mimes_filter( $mimes ) { return array( 'pdf' => 'application/pdf' ); } function wpse_59621_delay_mimes_filter( $value ) { if ( isset( $_REQUEST['post_id'] ) && get_post_type( $_REQUEST['post_id'] ) === 'my_post_type' ) add_filter( 'upload_mimes', 'wpse_59621_mimes_filter' ); else remove_filter( 'upload_mimes', 'wpse_59621_mimes_filter' ); return $value; } add_filter( 'wp_handle_upload_prefilter', 'wpse_59621_delay_mimes_filter' ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.