开发者

WordPress sql query on outside dbase how to display results?

I have two WP installs - both running 3.x but not multi-site (wish it were;-) I am querying wp install 1 for specific posts based on custom field to be displayed in wp install 2. My query is fine and returning results. The problem is I can get the results in the loop. This is what I'm using... I think it has something to do with the results returned being an array and not an object? Any help greatly appreciated!

  <?php  $hbldb = new wpdb('dbase','pass','user','localhost');


$results = $hbldb->get_results( "SELECT * FROM 
                                {$hbldb->wp_posts} wp_posts 
                                JOIN {$hbldb->wp_postmeta} wp_postmeta
                               开发者_StackOverflow ON wp_postmeta.post_id = wp_posts.ID
                                WHERE wp_postmeta.meta_key ='dbt_ffh_post'
                                AND wp_postmeta.meta_value = 'on'" );



 $pageposts = $hbldb->get_results($querystr, OBJECT);
?>




<?php if ($pageposts): ?>
  <?php global $post; ?>
  <?php foreach ($pageposts as $post): ?>
    <?php setup_postdata($post); ?>

    <div class="post" id="post-<?php the_ID(); ?>">


This is kind of late, but you might try this for your results. Haven't tested it but it should work.

if($pageposts) {       
    foreach($pageposts as $post)    
        echo '<div class="post" id="post-' . $post->guid . '">' . $post->post_title . '</div>';   
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜