SELECT * FROM $wpdb->posts WHERE ID > 160

8 nov. 2014, 15:16:26
Vizualizări: 28.5K
Voturi: 2

Aș dori să preiau toate articolele și etichetele aferente cu ID mai mare decât 160.

Am încercat:

'$args=array(
'post_type' => 'post',
'post_status' => 'publish', 
'posts_per_page' => 5,
'orderby'=> 'ID',
'order' => 'desc',
'meta_query' => array(
    array(
        'key'     => 'ID', // cheia meta
        'value'   => '160', // valoarea de comparat
        'type'   => 'numeric', // tipul de comparație
        'compare' => '>', // operatorul de comparație
        ),
    ),
  );


$the_query = new WP_Query( $args );

De asemenea am încercat

$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); ?>
  ....
2
Comentarii

Primul fragment de cod nu va funcționa deoarece interogarea meta nu poate ținti coloanele postărilor în acest fel. Al doilea pare să fie pe drumul cel bun, poți face o interogare doar pentru postări (fără elemente meta) pentru început?

Rarst Rarst
8 nov. 2014 16:06:25

Pot interoga tabelul wp_post fără probleme într-un alt script, dar am nevoie să interoghez folosind eticheta..

Albuquerque Web Design Albuquerque Web Design
9 nov. 2014 07:06:46
Toate răspunsurile la întrebare 1
0
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="Legătură permanentă către <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></b>
<small><?php the_time('j F Y') ?> <!-- de <?php the_author() ?> --></small><br/>    


9 nov. 2014 10:29:51