Problema con 'post__not_in'
16 ott 2011, 22:00:40
Visualizzazioni: 36.4K
Voti: 3
Sto eseguendo una query personalizzata sotto ogni post per ottenere altri post dalla sua categoria. Ora voglio escludere il post corrente. Questa è la mia Query:
<?php // post_correlati();
$exclude_post = $post->ID;
$cats = get_the_category();
//$cats[0]->term_id;$cats[1]->term_id; //nome
global $post;
$newQuery = new WP_Query('posts_per_page=5&orderby=rand&cat='.$cats[0]->term_id.'&post__not_in='.array($exclude_post).'');
if ( $newQuery->have_posts() ):?>
<ul>
<?php
while ( $newQuery->have_posts() ) : $newQuery->the_post(); ?>
<li>
<a title="<?php the_title();?>" href="<?php the_permalink();?>"><?php the_title();?></a>
</li>
<?php
endwhile;?>
</ul>
<?php
endif;
?>
Ora la mia query non mostra alcun risultato. Lo stesso accade se imposto il post da escludere per prova a 1 o simili.
Quale potrebbe essere l'errore nella mia query personalizzata?
Saluti Lars

Lars
53
Tutte le risposte alla domanda
1
0
Stai cercando di fornire un array come parte del parametro di query stringa. Potresti invece semplicemente fornire la lista degli argomenti come array in questo modo:
$newQuery = new WP_Query(
array(
'posts_per_page' => 5,
'orderby' => 'rand',
'cat' => $cats[0]->term_id,
'post__not_in' => array($exclude_post)
)
);

Joe Hoyle
2.2K
16 ott 2011 22:33:43
Domande correlate
1
risposte
2
risposte
4
risposte