Dynamic Featured Image - WordPress - is not getting the first featured image

I've installed the latest Dynamic Featured Image 3.1.2 and when I try to just print out the array of featured images on the page I only get Featured Image 2 and onward.

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <?php if( class_exists('Dynamic_Featured_Image') ) {
        global $dynamic_featured_image;
        $featured_images = $dynamic_featured_image->get_featured_images( );

        print_r( $featured_images );

        //You can now loop through the image to display them as required
    } ?>

    ... << rest of Post Loop >>

Even though I've added more than one Featured image it only shows from Featured Image 2 and on in the array.

Did I miss something else that I need to do?

Solutions

You can get all featured images including the default WordPress one using this function:

/**
 * Retrieve featured images for specific post(s) 
 * including the default Featured Image
 *
 * @since 3.1.2
 * @access public
 *
 * @see  $this->get_featured_images()
 *
 * @param Integer $post_id id of the current post
 *
 * @return Array An array of images or an empty array on failure
 */
public function get_all_featured_images( $post_id = null ) {

    if ( is_null( $post_id ) ) {
        global $post;
        $post_id = $post->ID;
    }

    $thumbnail_id = get_post_thumbnail_id( $post_id );

    $featured_image_array = array();
    if ( ! empty( $thumbnail_id ) ) {
        $featured_image = array(
            'thumb' => wp_get_attachment_thumb_url( $thumbnail_id ),
            'full' => wp_get_attachment_url( $thumbnail_id ),
            'attachment_id' => $thumbnail_id
        );
        $featured_image_array[] = $featured_image;
    }

    $dfiImages = $this->get_featured_images( $post_id );

    $all_featured_images = array_merge( $featured_image_array, $dfiImages );

    return $all_featured_images;

}

This function will be included in plugin in the next release. Till then you can add it to your dynamic-featured-image.php plugin file or you can download the and use the file from the master branch of github.

P.S. I am the author of the plugin.

What you are printing in your code are the custom Featured Images ( Featured Image 2 onwards) added by the plugin Dynamic Featured Image 3.1.2:

<?php if( class_exists('Dynamic_Featured_Image') ) {...

..while the first " Featured Image " in your Edit post screen is implemented in the wordpress core itself and can be printed using the the_post_thumbnail function (see http://codex.wordpress.org/Function_Reference/the_post_thumbnail).

Similar questions

Medium size image by plugin called dynamic featured image
i am using dynamic featured image and adding multiple product images to a single custom post type name as products for a single product but and i am trying to get those images in my template but the array only return me only two sizes [thumb] [full] but i need medium as well below is my code As you guys can see in the anchor tag $featured_image['me...
Featured Image not shown and getting error "Object of class WP_Error could not be converted to int"
First of all I'm using twentyeleven theme, I created a custom template page to insert posts. It has 4 submit forms. it is working well, also setting feature image is ok for 3 forms except the first one it is not setting feature image for the post even it upload the image (using upload form and also using image from link) and attach it to the post, ...
Multiple, Dynamic, Sidebars Problem - First Sidebar not working properly
This is my function: This does not work: BUT if I change the *is_active_sidebar* to 'Sidebar 2' or 'Sidebar 3', it works. For example, this works: I don't understand why this is. Any ideas?
Dynamic Dynamic WordPress Sidebars
It's always a drag trying to make sidebars the same height as the page content - too short and your page gets boring at the bottom, too long and your page looks like a run-on sentence. Is there any way to add/remove/display widgets based on content length, so that the sidebar will only display another widget if there's a ton of sidebar whitespace a...
wordpress dynamic content for dynamic pages
I am using wordpress for my next CMS project. Say I have a page template (full width page template) but the pages under that template have certain parts that are in one page but not in another . I am not talking about the content, the content comes from wordpress. I am talking about some specific parts of pages (say some images) which may be in one...
WordPress set featured image to first image of the post
I have tried every solution from similar answers and nothing seems to work on Wordpress 5.0 + When saving a post I want to set its featured image to the first image in the post content. In set_post_thumbnail() if I set the image id manually it works but it does not seem to pick up $images[0]->ID I'm not sure why this doesn't work. Note: I'm test...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy .