Title: Retrieving first image
Last modified: January 25, 2021

---

# Retrieving first image

 *  Resolved [darylaurito](https://wordpress.org/support/users/darylaurito/)
 * (@darylaurito)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/)
 * Hi Ajay, I can’t seems to get the first image in post right. Please advise thanks.

Viewing 15 replies - 1 through 15 (of 31 total)

1 [2](https://wordpress.org/support/topic/retrieving-first-image/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/retrieving-first-image/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/retrieving-first-image/page/2/?output_format=md)

 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13956276)
 * Will need more information – website URL and which posts are you referring to
   in particular. Lastly, what are you expecting to see and what you’re seeing
 *  Thread Starter [darylaurito](https://wordpress.org/support/users/darylaurito/)
 * (@darylaurito)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13957712)
 * I am getting custom post from custom field. My image return in image array so
   it return id when I inspect source.
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13960962)
 * A custom post shouldn’t be an issue as the plugin supports that. But, i’m not
   clear what do you mean custom field and the image array?
 * Please see my previous post as to what I would need to see
 *  Thread Starter [darylaurito](https://wordpress.org/support/users/darylaurito/)
 * (@darylaurito)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13963010)
 * > [View post on imgur.com](https://imgur.com/a/jDpPEJi)
 * I would like to get the first image from my post however now it is getting the
   featured image of my post. Is there a filter or setting to get the first image
   from my post? Please advise Ajay. Thanks
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13964448)
 * Thanks – I understand now. The featured image is the priority vs the first image.
   If the plugin can’t find the featured image, then it pulls the first image.
 * Please see the code here: [https://github.com/WebberZone/contextual-related-posts/blob/v3.0.3/includes/media.php#L118](https://github.com/WebberZone/contextual-related-posts/blob/v3.0.3/includes/media.php#L118)
 * The filter holding the thumbnail URL is: [crp_thumb_url](https://github.com/WebberZone/contextual-related-posts/blob/v3.0.3/includes/media.php#L182)
 *  Thread Starter [darylaurito](https://wordpress.org/support/users/darylaurito/)
 * (@darylaurito)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13967854)
 * Hi Ajay, thanks for the reply. Saw the code, does this mean I can set priority
   to displaying my custom image by specifying the meta name in that function and
   if my custom image is null then i will get the first image from post content?
   Please advise thank you.
 *  Thread Starter [darylaurito](https://wordpress.org/support/users/darylaurito/)
 * (@darylaurito)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13967882)
 * Also is the one you pointed out I can apply filter to it through my functions.
   php or i have to change the media.php file?
 *  Thread Starter [darylaurito](https://wordpress.org/support/users/darylaurito/)
 * (@darylaurito)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13967978)
 * I tried commenting out other options and only include get meta field name and
   getting first image from post. But it seems I keep getting image ID instead of
   URL. Please advise
 * Screenshots
 * > [View post on imgur.com](https://imgur.com/a/P0XS82t)
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13970738)
 * You are correct on the meta name. If you have a meta-field in the post that contains
   the direct URL of the image, then you can use that one. Alternatively, you can
   find this in the meta box at the bottom of the edit post screen – but with the
   original name (not the one in your screenshot).
 * Also alternatively, you can put a function in your functions.php to pull an image
   of your choice.
 * This should then `add_filter( 'crp_thumb_url', 'functionname' );`
 * You can borrow lines 132-145 which pulls out the image from the post content 
   and then tries to get the correct size thumbnail from there
    [https://github.com/WebberZone/contextual-related-posts/blob/v3.0.3/includes/media.php#L132-L145](https://github.com/WebberZone/contextual-related-posts/blob/v3.0.3/includes/media.php#L132-L145)
 *  Thread Starter [darylaurito](https://wordpress.org/support/users/darylaurito/)
 * (@darylaurito)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13973187)
 * Hi Ajay thanks for the reply.
 * Here is the meta box in my edit post screen. Do I put that in the meta field 
   settings.
 * Screenshot:
 * > [View post on imgur.com](https://imgur.com/a/mtcRuZf)
 * Thanks!
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13976033)
 * You need the full URL of the thumbnail so something like `https://sitename.com/
   image.png`
    -  This reply was modified 5 years, 4 months ago by [Ajay](https://wordpress.org/support/users/ajay/).
 *  Thread Starter [darylaurito](https://wordpress.org/support/users/darylaurito/)
 * (@darylaurito)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13976059)
 * Hi Ajay, so I can’t use the meta field name “article_header_image” ?
 *  Thread Starter [darylaurito](https://wordpress.org/support/users/darylaurito/)
 * (@darylaurito)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13976071)
 * Or I need to add in functions to parse the post meta array to image url?
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13979517)
 * If article_header_image already contains the full URL of the image then you don’t
   need to do anything else as the plugin should pick this up. However, if it doesn’t
   then you’ll need to reset it back to the default setting which is `post-image`
 *  Thread Starter [darylaurito](https://wordpress.org/support/users/darylaurito/)
 * (@darylaurito)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/retrieving-first-image/#post-13983964)
 * Hi Ajay, is there an example of the apply filter function? can’t seems to get
   the function

Viewing 15 replies - 1 through 15 (of 31 total)

1 [2](https://wordpress.org/support/topic/retrieving-first-image/page/2/?output_format=md)
[3](https://wordpress.org/support/topic/retrieving-first-image/page/3/?output_format=md)
[→](https://wordpress.org/support/topic/retrieving-first-image/page/2/?output_format=md)

The topic ‘Retrieving first image’ is closed to new replies.

 * ![](https://ps.w.org/top-10/assets/icon-256x256.png?rev=2986432)
 * [WebberZone Top 10 — Popular Posts](https://wordpress.org/plugins/top-10/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/top-10/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/top-10/)
 * [Active Topics](https://wordpress.org/support/plugin/top-10/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/top-10/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/top-10/reviews/)

## Tags

 * [image](https://wordpress.org/support/topic-tag/image/)

 * 31 replies
 * 2 participants
 * Last reply from: [Ajay](https://wordpress.org/support/users/ajay/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/retrieving-first-image/page/3/#post-14051558)
 * Status: resolved