2016-04-01 18 views
1

こんにちは私はランダムに投稿を表示するときに問題があります。 投稿がほぼ正しくリストされていますが、私はカスタムポストから2つのデータを取得するために条件meta_queyを実行していますが、コンテンツをプルすることは本当に確実ですが、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(); 


?> 

答えて

0

この引数は終了ASCに記事を並べ替えますので、arguments配列$args2から('order' => 'ASC')を削除してください。

単純に('orderby' => 'rand')が実行します。

$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', 

); 

私は、それはあなたのために働くの感謝を願っています!

関連する問題