SELECT*FROM$wpdb->帖子,ID>160

时间:2014-11-08 作者:Albuquerque Web Design

我想检索所有帖子和ID大于160的相对标签。

我试过:

\'$args=array(
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'posts_per_page\' => 5,
\'orderby\'=> \'ID\',
\'order\' => \'desc\',
\'meta_query\' => array(
    array(
        \'key\'     => \'ID\',
        \'value\'   => \'160\',
        \'type\'   => \'numeric\',
        \'compare\' => \'>\',
        ),
    ),
  );


$the_query = new WP_Query( $args );
也尝试过

$querystr = "
SELECT $wpdb->posts.* 
FROM $wpdb->posts, $wpdb->postmeta
WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id 
AND $wpdb->postmeta.meta_key = \'tag\' 

AND $wpdb->posts.post_status = \'publish\' 
AND $wpdb->posts.post_type = \'post\'
AND $wpdb->posts.ID > 160
ORDER BY $wpdb->posts.post_date DESC
 ";

$pageposts = $wpdb->get_results($querystr);

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

1 个回复
SO网友:Albuquerque Web Design
SELECT * FROM $wpdb->posts
LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
LEFT JOIN $wpdb->terms ON($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)

WHERE  $wpdb->posts.post_type = \'post\'
AND $wpdb->term_taxonomy.taxonomy = \'post_tag\'
AND $wpdb->posts.ID > 160 
ORDER BY $wpdb->posts.ID ASC
LIMIT 5

$pageposts = $wpdb->get_results($querystr);

if ($pageposts): ?>
<?php global $post; ?>
<?php foreach ($pageposts as $post):
setup_postdata($post); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<b><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></b>
<small><?php the_time(\'F jS, Y\') ?> <!-- by <?php the_author() ?> --></small><br/>    


结束

相关推荐

SQL - JOIN last child

我正在尝试进行一些自定义筛选。我需要加入最新的child post\\u作者。这似乎不太管用,它不断返回错误的孩子:SELECT * FROM wp_posts LEFT JOIN ( SELECT MAX(ID) as child_ID, post_parent, post_author as child_post_author FROM wp_posts WHERE post_type = \'ticket_reply\'