【发布时间】:2019-07-08 17:17:45
【问题描述】:
DB 新手在这里破解。我艰难地编写了一个 WP 模板文件,该文件从另一个站点的 WP DB 中检索帖子数据。它工作并且运行良好大约 2 年,然后突然停止工作 - 崩溃并且不允许页面完成加载。收到“网站遇到技术问题。”错误。
我注释掉了 ::prepare 方法以尝试隔离问题并且页面已完成加载,但仍然没有来自帖子的数据...这里又是一个完整的新手,所以我确信经验丰富的兽医可能会看到这个问题。感谢您的任何见解!
<?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(); ?>
【问题讨论】: