Tagged: x
-
AuthorPosts
-
June 2, 2016 at 12:04 pm #1022558
daveshu1234ParticipantHi,
I want to change the order of the posts in just 1 category to alphabetical.I used the code below that I found on the site in my functions file, but it changes the order in ALL categories. What is the correct code to just change the order in category id “4”?
add_action( 'pre_get_posts', 'x_category_order' ); function x_category_order($query){ if(!$query->is_main_query()) return $query; if(is_category('4')) $query->set( 'orderby', 'title' );$query->set( 'order', 'ASC' ); return $query; }June 2, 2016 at 7:04 pm #1023179
RadModeratorHi there,
Thanks for writing in.
Please change it into this,
add_action( 'pre_get_posts', 'x_category_order' ); function x_category_order($query){ if(!$query->is_main_query()) return $query; if(is_category('4')) { $query->set( 'orderby', 'title' ); $query->set( 'order', 'ASC' ); } return $query; }Cheers!
June 3, 2016 at 5:05 am #1023918
daveshu1234ParticipantPerfect – thank you!
June 3, 2016 at 8:27 am #1024161
JoaoModeratorYou are welcome.
Let us know if we can help you with anything else.
Thanks
Joao
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1022558 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
