Limit upload by file type only for certain custom post type

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’ ); Let us know how it goes – this is untested, … Read more

How to add a media with PHP

If I’m understanding correctly, each post has a filemaker, and each filemaker has only one photo? The structure is kind of unclear. Anyways, one way is top use media_sideload_image like below. However, media_sideload_image WON’T work with local files (a path on your filesystem), so you need to change your $file[‘url’] to be a valid URL … Read more

Edit image preview is not displayed

By default, wp-config.php might not have a closing tag ?> and this is acceptable and by design. The issue may arise from whitespace in some other .php file. In my case, I had whitespace after the closing tag of my functions.php file for my child theme. Once I removed that whitespace, the images are showing … Read more

Adding featured image via PHP

Use the set_post_thumbnail function. set_post_thumbnail( $post_ID, $thumbnail_id ); Require you use WordPress 3.1.0 or later. You need call this function after you have successfully created your post via wp_insert_post and have a valid $post_ID.

Image uploading stuck on “crunching”

Ok so i’m on wordpress 3.8.1 and i was having this issue and i tried EVERY FIX from every post i could find on this problem of the image upload staying stuck on “crunching” or having it say “image data does not exist” So apparently if the image dimensions (e.g. 1920×1080) are bigger than what … Read more

Using wp-uploads instead of wp-content/uploads

Well, after lots of digging (before and after posting this question), I think I figured it out. As @s_ha_dum suggests, the reason behind the odd directory placement is likely a personal preference of the person who created the Ubuntu “wordpress” package. Perhaps it makes for easier partitioning of permissions, or it makes updates more safe … Read more