My Wordpress website is special, because I mix Wordpress with external pages. The content of these pages is stored in a non-Wordpress database. I have scripts running once a day to generate all external pages. They use the Wordpress theme by including the following code:
define('WP_USE_THEMES', false);
require('../wp-blog-header.php');
This works fine for years. Now I tried to include these external content also in the Wordpress search results. I've found a way, by automatically copy the content of the external database into the wp_posts table of the WP database. These external records have a custom post type. I've also added the custom post type to the WP search through the functions.php. This works also fantastic!!
In the last step I tried to apply images to these 'special' search results. The images are stored in an external directory. Not in the WP images folder. My daily script adds these features image urls by adding new wp_posts rows for attachments and wp_postmeta rows to connect them to the post. Looks exactly like the native WP posts entries.
Unfortunately it doesn't work: The search results display the text content, but no image. I have also tried to generate all WP sizes of this images and it doesn't work either. The tag shows just 'unknown', when examining the source code. The link in the guid field of the wp_posts table is correct, but links to an external directory.
Do I have to copy all external images into the WP images folder, in order to make it work?
Or is there another better option?
Meanwhile I've found a suitable solution. I just modified the theme's search.php and added
if(get_post_type() == 'my_custom_post_type')
{
$post_thumbnail_url = get_the_guid(get_post_thumbnail_id());
}
This way I can use the Image url, which I've stored in the guid field of the attachments post row.