get_post aléatoire et ordre en ne fonctionnant pas
-
-
Ilmanque desguillemets simples sur le `ASC` ..juste unefaute defrappe oupeut-être lié?Missing single quotes on the `ASC`.. just a typo or possibly related?
- 1
- 2011-03-23
- t31os
-
Pourriez-vous êtreplusprécis sur ce quine fonctionnepas (parexemple,votre codene renvoie-t-il aucun résultat ou ...)?Could you be more specific on what's not working (e.g. does your code not return any results or ...)?
- 0
- 2011-03-23
- Manzabar
-
@t31los,aessayé les citations -mercimaistoujourspas de chance. @Manzabar -merci -j'aimis àjour lesinformations.Les résultats sont retournés 'order,orderby,rand'ne prennentpaseffet.Merci.@t31los, tried the quotes - thanks but still no luck. @Manzabar - thank you - I've updated the information. Results are returned 'order, orderby, rand' do not take effect. Thanks you.
-
7 réponses
- votes
-
- 2011-10-21
Oui,c'est la syntaxe correcte:
$args = array( 'orderby' => 'rand', 'order' => 'ASC' ); query_posts( $args );
Cependant,lespluginspeuventempêcher cela defonctionner correctement. Essayez de désactiver lesplugins TOUS et voyez si cela vous aide. Deuxplugins connus quiempêchent
orderby=rand
defonctionner sontPost Type Order
etWP_Sticky
Deplus,si la commande Types depublicationestinstallée,assurez-vous de visiter lapage d'administrationet de vérifier lesparamètres. Vouspouvez utiliser cepluginet l'empêcher de réorganiser automatiquement les articles:
http://img829.imageshack.us/img829/2616/pictureot.png
Etpuis vouspouvez utiliser le codepour l'ordre destypes demessagespour ordonner spécifiquement ces articles auxendroits où vousen avezbesoinpour être commandés via l'ordrepersonnalisé/menu. Voici l'exemple de codepour ceplugin:
Le code PHP suivant renverratoujours lemessage dans l'ordre de configuration:
$args = array( 'post_type' => 'feature' ); $my_query = new WP_Query($args); while ($my_query->have_posts()) { $my_query->the_post(); (..your code..) }
Ou:
$posts = get_posts($args); foreach ($posts as $post) { (..your code..) }
Si letri automatiquen'estpas coché,vous devrez utiliser lesparamètres "orderby"et "order":
$args = array( 'post_type' => 'feature', 'orderby' => 'menu_order', 'order' => 'ASC' );
Yes, this is the correct syntax:
$args = array( 'orderby' => 'rand', 'order' => 'ASC' ); query_posts( $args );
However plugins can keep this from working properly. Try disabling ALL plugins and see if that helps. Two known plugins which keep
orderby=rand
from working arePost Type Order
andWP_Sticky
Also, if you have Post Types order installed make sure you visit the Admin page and check the settings. You can use this plugin and keep it from automatically re-ordering posts:
http://img829.imageshack.us/img829/2616/pictureot.png
And then you can use the code for Post Types Order to specifically order those posts in places where you need them to be ordered via the custom/menu-order. Here is the example code for that plugin:
The following PHP code will still return the post in the set-up Order:
$args = array( 'post_type' => 'feature' ); $my_query = new WP_Query($args); while ($my_query->have_posts()) { $my_query->the_post(); (..your code..) }
Or:
$posts = get_posts($args); foreach ($posts as $post) { (..your code..) }
If the Auto Sort is uncheck you will need to use the "orderby" and "order" parameters:
$args = array( 'post_type' => 'feature', 'orderby' => 'menu_order', 'order' => 'ASC' );
-
Mercipour l'information."Commandeintuitive demessagespersonnalisés" cause définitivement ceproblème!Thanks for the heads-up. "Intuitive Custom Posts Order" definitely causes this problem!
- 0
- 2015-08-25
- Mr_Chimp
-
C'était étrangementpréciset juste.L'ordre destypes deposte l'afait.Merci!This was oddly specific and right. Post Types Order did it. Thanks!
- 1
- 2016-11-10
- Allen Gingrich
-
Jen'utilisepas ceplugin,mais denombreuxexemples sur wordpress.org utilisent "sort_order" au lieu de "order",ce quin'apasfonctionné,alors que c'est le cas.Merci.I'm not using that plugin, but many of the examples on wordpress.org use "sort_order" instead of "order", which didn't work, whereas this does. Thanks.
- 0
- 2017-03-09
- dw1
-
- 2020-02-20
Si vous êtes hébergé sur WP Engine,vous devez activermanuellement le classement aléatoire dans vosparamètres oubien
'orderby' => 'rand'
ne fonctionnerapas.https://wpexplorer-themes.com/total/docs/ordre-aléatoire-wpengine/
If you're hosted on WP Engine, you need to manually enable random ordering in your settings or else
'orderby' => 'rand'
won't work.https://wpexplorer-themes.com/total/docs/random-order-wpengine/
-
merci qui a aidé.thanks that one helped.
- 0
- 2020-04-29
- M Haseeb
-
- 2011-03-23
Pourquoin'essayez-vouspas d'utiliser query_posts à laplace?
Quelque chose comme:
$args = array( 'orderby' => 'rand', 'order' => 'ASC' ); query_posts( $args );
Why don't you try to use query_posts instead?
Something like:
$args = array( 'orderby' => 'rand', 'order' => 'ASC' ); query_posts( $args );
-
Merci àtouspour votre aide,stupidemoi - c'étaiten conflit avec unplugin 'Post Type Order' (Commander des objets detypes depublicationen utilisant une capacitéjavascripttriableparglisser-déposer)Thank you all for your help, silly me - it was conflicting with a plugin 'Post Type Order' (Order Post Types Objects using a Drag and Drop Sortable javascript capability)
-
- 2011-11-28
essayez ce code
<?php remove_all_filters('posts_orderby'); query_posts('orderby=rand'); ?>
a obtenu la réponse d'ici
http://www.reinaris.nl/wp/wordpress-random-post-order-not-working-orderbyrand/
try this code
<?php remove_all_filters('posts_orderby'); query_posts('orderby=rand'); ?>
got the answer from here
http://www.reinaris.nl/wp/wordpress-random-post-order-not-working-orderbyrand/
-
-
- 2016-01-09
J'ai rencontré lemêmeproblèmeet j'ai heureusementtrouvé cefil.J'aiessayé une solution différente,probablementplus sale que les autres,maispeut-être utile dans certains cas.
Engros,j'ai mélangé lesmessages avant de lespublier:
<?php $selectedPosts = get_posts($args); shuffle($selectedPosts); foreach ($selectedPosts as $selectedPost) : setup_postdata( $selectedPost ); ?> <!-- post elements here --> <?php endforeach; wp_reset_postdata(); ?>
I ran into the same problem, and luckily found this thread. I tried a different fix, probably dirtier than the others, but maybe useful in some cases.
Basically, I shuffled the posts before outputting them:
<?php $selectedPosts = get_posts($args); shuffle($selectedPosts); foreach ($selectedPosts as $selectedPost) : setup_postdata( $selectedPost ); ?> <!-- post elements here --> <?php endforeach; wp_reset_postdata(); ?>
-
- 2019-01-03
Si vous avez wp-engine dans votre site WordPress,cochez l'option ALLOW ORDER BY RAND ().Consultez un articleici: https://wpengine.co.uk/support/ordre-par-rand/
If you have wp-engine in your WordPress site check the ALLOW ORDER BY RAND() option. See an article here: https://wpengine.co.uk/support/about-order-by-rand/
J'ai ce code qui renvoie la liste dutitre de l'article sousforme de liens,mais lorsquej'ajoute lesparamètres 'orderby'et 'order' -il renvoie des résultatsmais 'orderby,order,rand'ne fonctionnepas,quelqu'unpeut-ilme dire quoiJe vaismal?Merci!