DB newbie hack here. I slogged my way through coding up a WP template file that retrieves the post data from another site's WP DB. It worked and was functioning fine for about 2 years and suddenly stopped working - crashing and not allowing the page to finish loading. Getting an 'The site is experiencing technical difficulties.' error.
I commented out the ::prepare method to try and isolate the issue and the page finished loading but still no data from the posts... again full novice here so I'm sure a seasoned vet could probably see the issue. Thanks for any insight!
<?php
$originaldb = new wpdb('XXXXXX','XXXXXX','XXXXXX','XXXXXXXX');
//Home Recent POST
$post_id_recent = get_field('recent_post_id');
$prep_recent = $originaldb->prepare("SELECT * FROM wp_posts WHERE $wpdb->posts.ID = $post_id_recent");
$recent = $originaldb->get_results($prep_recent);
$prep_recent_thumb = $originaldb->prepare("
SELECT p1.*, wm2.meta_value FROM wp_posts p1 LEFT JOIN
wp_postmeta wm1 ON (
wm1.post_id = $post_id_recent
AND wm1.meta_value IS NOT NULL
AND wm1.meta_key = '_thumbnail_id'
)
LEFT JOIN wp_postmeta wm2 ON (wm1.meta_value = wm2.post_id AND wm2.meta_key = '_wp_attached_file'
AND wm2.meta_value IS NOT NULL) WHERE p1.post_status='publish' AND p1.post_type='post'
");
$recent_thumb = $originaldb->get_results($prep_recent_thumb);
foreach ($recent_thumb as $obj) :
$url = $obj->meta_value;
endforeach; ?>
<?php foreach ($recent as $obj) : ?>
<div class="home_recent_thumb" style="background-image:url(<?php echo 'http://kuteblackson.com/blog/wp-content/uploads/'.$url; ?>)" onclick="location.href='<?php echo $obj->guid; ?>';"></div>
<div class="home_recent_content">
<div class="home_recent_title"><a href="<?php echo $obj->guid; ?>"><?php echo $obj->post_title; ?></a></div>
<div class="home_recent_excerpt"><?php echo $obj->post_excerpt; ?></div>
<a href="<?php echo $obj->guid; ?>" class="button medium radius home_blog_button">READ BLOG</a><br>
<a href="blog" style="font-size: 16px; color: #9e9898; text-decoration:underline;">See all blog posts</a>
</div><!-- end .home_recent_content -->
<div style="clear:both;"></div>
<?php endforeach; wp_reset_query(); ?>