Wordpress查询另一个wordpress数据库for循环
I've been really stuck on this and on a tight deadline, basically there is two different wordpress installations. I will call the database which would be to main content: database1 and the one that the content would be loop onto: database2
我一直坚持这个,并在一个紧迫的截止日期,基本上有两个不同的wordpress安装。我将调用主要内容的数据库:database1和内容将循环到的数据库:database2
Basically what I need to happen is the content from database1 to be displayed onto database2 in a loop, with metabox information, title, date, and featured image. This is how far I have gotten so far, this only shows the title and the date.
基本上我需要发生的是来自database1的内容在循环中显示到database2上,包含元数据信息,标题,日期和特色图像。到目前为止,我已经走了多远,这只显示了标题和日期。
<?php
$originaldb = new wpdb('blank', 'blank', 'blank', 'blank');
$results = $originaldb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type='press' AND post_status='publish' ORDER BY post_date DESC LIMIT 30" );
if($results):
foreach($results as $post): setup_postdata($post);?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<!-- Post Thumbnail -->
<?php the_post_thumbnail(); ?>
<!-- /Post Thumbnail -->
<div class="caption">
<div class="presslink"><a href="<?php $key_1_value = get_post_meta($post->ID, 'presslink', true); if($key_1_value != '') { echo $key_1_value; } ?>" target="_blank" title="<?php the_title(); ?>"><?php the_title(); ?></a></div>
<div class="pressdate"><a href="<?php $key_1_value = get_post_meta($post->ID, 'presslink', true); if($key_1_value != '') { echo $key_1_value; } ?>" target="_blank" title="<?php the_title(); ?>"><?php echo get_the_date('M Y'); ?></a></div>
</div>
</article>
<?php endforeach; ?>
<?php else: ?>
Testing has failed
<?php endif; ?>
Any help would be great, I'm not that versed in PHP and SQL.
任何帮助都会很棒,我不熟悉PHP和SQL。
3 个解决方案
#1
0
if you are getting the post id. you can try using
如果你得到了帖子ID。你可以尝试使用
<?php
$post_id=get_the_ID();
echo get_the_post_thumbnail( $post_id); ?>
hope this will work for you
希望这对你有用
更多相关文章
- 使用date_default_timezone_set和日期的可能的PHP bug ?
- 关于PHP 读取EXCEL时间(不是日期)的问题
- 数据库分卷备份 thinkphp3.2版
- 速率结构的数据库/算法
- 使用php codeigniter进行Mysql数据库同步
- php中三种数据库的连接方式
- 无法从Ajax POST请求中将带空格的数据导入数据库
- Laravel 5验证日期为php Y格式。g 2015 ?
- 将纪元时间转换为日期PHP