Title: Multiple Custom Fields
Last modified: April 11, 2022

---

# Multiple Custom Fields

 *  Resolved [mian117](https://wordpress.org/support/users/mian117/)
 * (@mian117)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/multiple-custom-fields-10/)
 * Hi [@h](https://wordpress.org/support/users/h/)éctor Cabrera,
    I want to make
   a fallback image request, if there is no featured image attached then it should
   look for the custom field and then display that image. is there any possibility
   for this, please let me know the file name, I tried some code changes in image.
   php and output.php, but it didn’t work. Thank You

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/multiple-custom-fields-10/#post-15547998)
 * Hi [@mian117](https://wordpress.org/support/users/mian117/),
 * Making changes to plugin’s code (or to a third-party theme) is not a good WordPress
   development practice: the next time you update the plugin WordPress will replace
   your modified plugin files with the stock ones automatically, undoing all of 
   your plugin modifications.
 * Instead, please use the built-in hooks that the plugin provides so you can make
   changes to it without having to modify its code – like so for example:
 *     ```
       <?php
       /**
        * Renders an alternative thumbnail from a custom field
        * if the post doesn't have a thumbnail.
        *
        * @author Hector Cabrera
        * @see    https://wordpress.org/support/topic/multiple-custom-fields-10/
        *
        * @param  string  $img_url  The default 'No thumbnail' image URL
        * @return string  $img_url  The (modified) 'No thumbnail' image URL
        */
       function wpp_thumbnail_fallback( $img_url, $post_id ) {
   
           // Post  doesn't have a thumbnail so let's fallback 
           // to the custom field one
           if ( ! has_post_thumbnail( $post_id ) ) {
               // Get the image URL from your custom field here
               // and then assign it to $img_url or return your URL
               //
               // eg. $img_url = get_post_meta( $post_id, 'MY_CUSTOM_FIELD_IMG_URL', true );
           }
   
           return $img_url;
   
       }
       add_filter( 'wpp_default_thumbnail_url', 'wpp_thumbnail_fallback', 10, 2 );
       ```
   
 * If you have any other questions don’t hesitate to ask, ok?
 *  Thread Starter [mian117](https://wordpress.org/support/users/mian117/)
 * (@mian117)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/multiple-custom-fields-10/#post-15549026)
 * I’m impressed with this fast response. Thank You very much.
    This solution solved
   the problem. I have tweaked it a bit to work as per my requirement for more than
   1 custom field.
 *     ```
       /**
        * Renders an alternative thumbnail from a custom field
        * if the post doesn't have a thumbnail.
        *
        * @author Hector Cabrera
        * @see    https://wordpress.org/support/topic/multiple-custom-fields-10/
        *
        * @param  string  $img_url  The default 'No thumbnail' image URL
        * @return string  $img_url  The (modified) 'No thumbnail' image URL
        */
       function wpp_thumbnail_fallback( $img_url, $post_id ) {
   
           // Post  doesn't have a thumbnail so let's fallback 
           // to the custom field one
           if ( ! has_post_thumbnail( $post_id ) ) {
               // Get the image URL from your custom field here
               // and then assign it to $img_url or return your URL
       		if( get_field('graphic_910x512', $post_id) ){
                 		$image_url_linkedin = get_field('graphic_910x512', $post_id);
       				$img_url =  $image_url_linkedin['url'];
       		}
       		else if( get_field('graphic_683x512', $post_id) ){
                 		$image_url_linkedin = get_field('graphic_683x512', $post_id);
       				$img_url =  $image_url_linkedin['url'];
       		}
       		else if( get_field('xxl_graphic', $post_id) ){
                 		$image_url_linkedin = get_field('xxl_graphic', $post_id);
       				$img_url =  $image_url_linkedin['url'];
       		}
   
           }
   
           return $img_url;
   
       }
       add_filter( 'wpp_default_thumbnail_url', 'wpp_thumbnail_fallback', 10, 2 );
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Multiple Custom Fields’ is closed to new replies.

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

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [thumbnail](https://wordpress.org/support/topic-tag/thumbnail/)

 * 2 replies
 * 2 participants
 * Last reply from: [mian117](https://wordpress.org/support/users/mian117/)
 * Last activity: [4 years, 1 month ago](https://wordpress.org/support/topic/multiple-custom-fields-10/#post-15549026)
 * Status: resolved