web-dev-qa-db-ja.com

$ wpdb->ポストから選択してくださいWHERE ID> 160

160を超えるIDを持つすべての投稿と相対タグを取得したいです。

私は試した:

'$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); ?>
  ....
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/>