【发布时间】:2016-07-21 15:15:47
【问题描述】:
您好,我在随机显示帖子时遇到问题。 帖子几乎正确列出,我正在做一个条件 meta_quey 以从自定义帖子中捕获 2 个数据,并且确实可以确定拉取内容,但是 rand 属性的 orderby 仅更改位置的前 2 个帖子,我想做随机所有帖子有人对此有解决方案吗?
感谢您的帮助!
$args2 = array (
'post_type' => 'garotas',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'cidade',
'value' => 'SL',
// 'compare' => 'LIKE'
),
array(
'key' => 'garotastop',
'value' => 1,
// 'compare' => 'LIKE'
)
),
'posts_per_page' => -1,
'orderby' => 'rand',
'order' => 'ASC',
);
$event_query2 = new WP_Query( $args2 );
// The Query
$the_query2 = new WP_Query( $args2 );
// The Loop
if ( $the_query2->have_posts() ) {
while ( $the_query2->have_posts() ) {
$the_query2->the_post();
$title = get_the_title();
$separator = "-";
$title2 = str_replace(" ", $separator, $title);
$width = 300;
$height = 700;
echo '<li class="col-md-4"><h1 class="title5 conteudoTitulo cor1 title-list"><a href="http://garotasjp.com.br/garotas/'.$title2.'">' . get_the_title() . '</a></h1>';
echo "<div class='thumbnail3'>";
$garotastop1 = get_post_meta( $post->ID,'garotastop1', true );
$imageUrl = wp_get_attachment_image_src($garotastop1, full);
echo '<a href="http://garotasjp.com.br/garotas/'.tirarAcentos($title2).'"><img class="img-responsive" width="'.$width.'" height="'.$height.'" src="'.$imageUrl[0].'"/></a>';
echo "</div>";
echo "</li>";
}
}
/* Restore original Post Data */
wp_reset_postdata();
?>
【问题讨论】:
标签: php wordpress loops random