When using [gallery royalslider="1" id="post_id"] slider does not find the featured image.

abaileytn's Avatar


01 Jan, 2015 03:28 PM

Found one gotcha when using the post id to find images attached to a post.

Scenario is when using an single image multiple times as the featured image for various posts.
When the imag eis assigned as the featured image to a post, that attachment record has it's post_parent set to the post it' a featured image to and sets the _thumbnail_id meta value for that post.

When the same image is assigned multiple times to different posts, the post_parent field points only to the last one assigned. But the _thumbnail_id remains on all the posts where it was assigned as a feature image.

This leads to RoyalSlider not finding the feature image because apparently it only checks for the post_parent relationship. This gives a no image found error message.

What should happen is that both the post_parent AND the _thumbnail_id should be checked so all images are included. Or at least a switch so the feature image can be included if needed if you feel including the feature image is incorrect..

  1. Support Staff 1 Posted by Dmitry Semenov on 01 Jan, 2015 07:57 PM

    Dmitry Semenov's Avatar


    Gallery shortcode should contain only attachment post ID's, if you need to create slider from posts - use Posts Slider - http://help.dimsemenov.com/kb/wordpress-royalslider-tutorials/wp-cr...


  2. 2 Posted by abaileytn on 01 Jan, 2015 09:11 PM

    abaileytn's Avatar

    I believe you are misunderstanding me.

    I want to make a slider that displays all the attachments AND the featured image for one post. A Gallery style slider works fine for attachments but may not include the feature image because the feature image may not be attached to the post. It may only be referenced in the "_thumbnail_id" meta data for a given post.

    Note the difference between

    [gallery idS="a list of attachment ids"]
    [gallery id="a post id"] //Not an attachment id but a single post id. this means the gallery will contain all the images for that single post.

    As I pointed out above. the feature image may Not be attached because the was assigned as a feature image to multiple posts. The attachements post_parent can only point to one post so the last assignment is actually attached. All others are not attached but are referenced as the featured image and display as such.

    All the other assignments come through the "_thumbnail_id" meta data.

    I found a way to do it fairly easily. In GalleryShortcode.php Just below line 78 in the current version. I added.

    $thumbnail_id = get_post_meta( $id, '_thumbnail_id', true);
    if( !empty($thumbnail_id) ) {
      $attachment = get_post($thumbnail_id);
      if( !empty($attachment) ){
        $attachments[$thumbnail_id] = $attachment;

    This makes sure that if the thumbnail is not attached that it is still added to the $attachments list.

  3. Support Staff 3 Posted by Dmitry Semenov on 02 Jan, 2015 01:52 PM

    Dmitry Semenov's Avatar

    Oh, indeed I did misunderstand you.

    Do you know if default [gallery] with default WP theme does this? I'll take a look at this issue on next week and will push update to CodeCanyon.

    Thank you.

  4. 4 Posted by abaileytn on 02 Jan, 2015 03:52 PM

    abaileytn's Avatar

    Yes the current native [gallery] shortcode takes the ID= attribute and returns all the attached images. It does not display a thumbnail if it is not attached, which is the same bug, assigning the same attachment as a feature image to multiple posts.

    But I consider that a bug on the part of WordPress. :)

    When you add the modification you might want to also check the Exclude parameter to see if the thumbnail_id is excluded.

    On other point. With the native [gallery], if the gallery is empty it just displays nothing. In the royal slider it displays an ugly error message.

    [RoyalSlider Error] No post attachments found.

    Looks bad on the screen and isn't really an error, just an empty set.

    Thanks for the attention. I really like the slider and your Magnific popup

  5. 5 Posted by abaileytn on 25 Jul, 2018 08:24 PM

    abaileytn's Avatar

    This is a late followup. I patched my own copy to fix this and this is the first time I needed to update the slider. May I suggest you add this to the slider to allow it to pickup up multiply assigned thumbnails that are not attached.

    In GalleryShortcode.php at about line 80 Add.

        $thumb_id = get_post_meta($id, '_thumbnail_id', true);
            $attachments[$thumb_id] = get_post($thumb_id);

    if ( empty($attachments) ){
    return NewRoyalSliderMain::frontend_error(__('No post attachments found.', 'new_royalslider'));

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac