2016-04-01 20 views
1

Hallo Ich habe ein Problem beim Anzeigen von Posts nach dem Zufallsprinzip. Die Beiträge sind fast korrekt aufgelistet, ich mache eine Bedingung Meta_query, um 2 Daten aus dem benutzerdefinierten Beitrag zu fangen und ist wirklich sicher ziehen Inhalt, aber die Reihenfolge durch das Attribut rand ändert nur die ersten 2 Stellen der Position und ich möchte alle Posts zufällig machen Hat jemand eine Lösung dafür?Benutzerdefinierte Post Random Wordpress

Danke für Hilfe!

$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(); 


?> 

Antwort

0

Versuchen zu entfernen ('order' => 'ASC') von Argumenten Array $args2, weil dieses Argument Beiträge in ASC endet neu anordnen wird.

Einfach ('orderby' => 'rand') wird die Aufgabe erledigen.

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

); 

Ich hoffe, es funktioniert für Sie, danke!

Verwandte Themen