I cannot get my WordPress theme to randomise the posts I’m displaying in the category archives [I’m using it as a CMS]. The homepage randomises normally, and I am [I think] correctly altering the WP_query. Below is the exact args array:
array(4) { ["orderby"]=> string(4) "rand" ["order"]=> string(3) "ASC" ["posts_per_page"]=> string(2) "-1" ["category_name"]=> string(8) "branding" }
For easier reading it is:
orderby => rand
order => ASC
posts_per_page => -1
category_name => branding (or whatever the query_string brings in)
I get all the posts from the category, but they are in post date order.
Any clues? or alternate methods for shuffling the result of my WP_query in the have_posts?
Thanks.
************EDIT************
Sorry I should have been more clear about the args array above. It is a var_dump of the query array, not my arguments I am adding to the query.
$args = array(
'orderby' => 'rand',
'order' => 'ASC',
'posts_per_page' => '-1',
);
global $wp_query;
remove_all_filters('posts_orderby');
$theq = array_merge($args, $wp_query->query);
query_posts($theq);
I added the remove_all_filters as per Sheikh Heera suggestion, but it hasn’t made a difference.
You might be better off creating a new query then. This should only be used on an taxonomy template though like category.php or taxonomy-yourcustomtaxonomy.php.
It could be another plugin that creating the problem but you can do as follows
But remember, you can wreck a plugin’s functionality with this solution, but it could be useful to solve the problem but may be not perfect.
I think you want to be merging it with the original query. No need to specify the category then, and works if it’s using a custom taxonomy this way too.