• 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: 3333

    So 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).

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Dumitru Brinzan

    (@ilovewpcom)

    Unfortunately the fix above fixes only a part of the issue. I went through the whole plugin and fixed it properly. The full code is here: https://pastebin.com/9BFvcb5q

    I tried this with WP version 4.7.1 and it didn’t work. Problem was that after selecting an image as an additional thumbnail, the pop-up window closes but the image doesn’t appear in the page’s thumbnail settings. If I save the page and preview it in the browser, the image doesn’t appear there either.

    I rolled back to Multiple post thumbnails – plugin version 1.3. and that works correctly also with 4.7.1. but the style of the pop-up window is not as good as with 1.6.6 version. So can anyone help me to do some fixes to 1.6.6. (or 1.7.) version so that it would work with WP 4.7.1 also?

    • This reply was modified 7 years, 10 months ago by karhu.
    • This reply was modified 7 years, 10 months ago by karhu.
    Thread Starter Dumitru Brinzan

    (@ilovewpcom)

    You have to take the code from here – https://pastebin.com/9BFvcb5q – , it is a complete fix, don’t just take the line in the original message in the thread.

    Hi, I did take the whole code from here ( https://pastebin.com/9BFvcb5q) but the plugin worked same way as with 1.6.6 version – meaning it didn’t work. Perhaps my error is something else than what you version 1.7 fixes?

    hi.the post types that I want to have secondary image, are posts & pages.
    the codes I put in function.php are these lines below:

    
    //secondary Thumbnail
    if (class_exists('MultiPostThumbnails')) {
    
    new MultiPostThumbnails(array(
    'label' => 'Secondary Image',
    'id' => 'secondary-image',
    'post_type' => array('post','page')
     ) );
    
     }
    

    and the plugin is edited as you said. in back end everything is ok but I dont have secondary image in pages.

    please help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘(BUGFIX) Bug with Multiple Post Types (WP 4.5+)’ is closed to new replies.