orderby rand does not work with Posts in descendant category
-
Hi there,
even though I could display all the posts in the descendant categories by entering the parent category id as parameter of category=”{}” but the orderby does not work with the posts in the descendant categories.
Please advise, thank you!!
-
Can you please provide the full shortcode which you are using? So I will take a look and try to understand the scenario.
[psac_post_carousel limit=”3″ show_tags=”false” show_author=”false” show_category=”false” show_date=”false” category=”2″ show_content=”false” dots=”false” orderby=”rand” sliderheight=”300″ ]
so all of the posts are belong to the descendant categories of category 2 but orderby=”rand” is not working, they always orderby title
Thanks for the shortcode and it looks OK. I have tested the same shortcode in my local and it is working perfectly.
Can you please tell me which hosting are you using? Because some hosting company disable the order by random.
Is there any plugin active which can modify the WP Query behavior?
One more thing, Its only orderby=”rand” or none of the orderby parameter is working.
Hi there,
thank you for your reply and the idea. Yes, there is a WP Query in the archive.php, but the WP Query is to list out the posts, not the gallery above them.
If that is the case, how can I set a condition to differentiate both of them?
Please advise, thank you!
Sorry but I am not asking about the WP Query in archive.php file actually I am saying that
Can you please tell me which hosting you are using? Because some hosting companies disable the order by random.
Is there any third party plugin active which can modify the WP Query behavior via Hook or Filter?
Also one more thing, Its only orderby=”rand” or none of the orderby parameters is working.
Hi there,
thank you for the follow up, let me give you more detail. the shortcode is within the archive.php file by using do_shortcode(). And within the archive.php there is a custom WP Query which is order by title and it is for sorting the category posts. The gallery is above the list of category posts.
I dont know if the custom WP Query affect the gallery order, if so, how to solve this?
Thank you!!
Sorry for the delayed response. No should not affect. Both queries are independent and it will work independently.
Can you give me your web page URL? So I can take a look and try to understand the scenario. One more thing to confirm as per your response, Order By is not working in your Gallery plugin or in Post Slider and Post Carousel Plugin.
Thank you for your reply, the site is still under developing so it is not allow to show to public, but I could give you the code in archive.php. So the new WP_Query is just right under the shortcode and category “a_category” has ID: 2 . And the gallery is always order by title. thank you!!
echo do_shortcode( ‘[psac_post_carousel limit=”6″ show_tags=”false” show_author=”false” show_category=”false” show_date=”false” category=”2″ show_content=”false” dots=”false” orderby=”rand” sliderheight=”300″ ]’ );
$query_two = new WP_Query(
array(
‘category_name’=>’a_category’,
‘post_status’ => ‘publish’,
‘post_type’ => ‘post’,
‘posts_per_page’ => -1,
‘orderby’ => ‘post_title’,
‘order’ => ‘ASC’
)Thanks for the code. The first part is “Post Slider and Post Carousel” which has orderby random and second part is another query (Query 2) which has orderby post title.
Both are individual query and works independently. Have you tried another orderby parameter in Post Slider and Post Carousel shortcode just to understand only orderby random is not working or others are also?
Some hosting disable the orderby random due to performance issue and sometime third party plugin interrupt the WP Query also by hooks.
Hi there,
just found out that we got another function in the functions.php which caused the order not as expected:
add_action( ‘pre_get_posts’, ‘my_change_sort_order’);
function my_change_sort_order($query){
if(is_archive()):
$query->set( ‘order’, ‘ASC’ );
$query->set( ‘orderby’, ‘title’ );
endif;
}do you know if there is anyway to overwrite this function “just” for that gallery slider??
Thank you
Thanks for your response. Yes,
add_action( ‘pre_get_posts’, ‘my_change_sort_order’);is changing the order of Post Slider and Post Carousel plugin query.Your function will change query parameter for every archive page because of this condition
if(is_archive()):As per your response on Dec 08, 2024, In archive page you have a Post Slider and Post Carousel plugin shortcode and below it there is a WP Query which is fetching the record of particular category
a_categoryand query is orderby post_title in ASC.So the function in the functions.php is not necessary if you had placed for this archive page only. Is this function used for any other archive page?
If not then simply comment it and every thing will work normal.
The topic ‘orderby rand does not work with Posts in descendant category’ is closed to new replies.