(BUGFIX) Bug with Multiple Post Types (WP 4.5+)
-
Hi,
I’ve started using this plugin in 2016 and it was working fine for my posts.
I have then added a new custom post type and have modified the code in functions.php like this:new MultiPostThumbnails( array( 'label' => 'Secondary Image', 'id' => 'secondary-image', 'post_type' => array('post','testimonial') ) );
It was working at first, but after WordPress update to 4.5.2 or 4.5.3 it stopped (half-way).
The “Secondary Image” image upload was still appearing in the right places, for both Posts and Testimonial posts, but on the front-end it wasn’t. It was working well with EXISTING thumbnails, but not with NEW thumbnails.So I decided to get to the bottom of it.
In your wp_postmeta table, if you have MULTIPLE post types like I have above, the plugin creates a new row like this:
meta_id: 1111
post_id: 2222
meta_key: Array_secondary-image_thumbnail_id
meta_value: 3333So it is obvious that the plugin simply doesn’t store correctly the meta_key in the table if you are using multiple post types.
The FIX to this is SIMPLE:
Go to /wp-content/plugins/multiple-post-thumbnails/multi-post-thumbnails.php and find line #444, it looks like this:
$this->set_meta($post_ID, $this->post_type, $this->id, $thumbnail_id);
change it to this:
$this->set_meta($post_ID, get_post_type($post_ID), $this->id, $thumbnail_id);
The issue is that the plugin uses the custom post type that is defined in your functions.php and uses it as a string ONLY when adding the meta field to the DB, it doesn’t check if it is an array or a string.
This fixes the issue, but you will have to re-apply your featured images to the posts in which it wasn’t working (as it wasn’t saving them correctly).
- The topic ‘(BUGFIX) Bug with Multiple Post Types (WP 4.5+)’ is closed to new replies.