CodeIn House

  • Laravel
  • WordPress
  • jQuery
  • Javascript
  • Contact
Home   WordPress   How to Reorder Post within Category in WordPress Without any ...

How to Reorder Post within Category in WordPress Without any WordPress Post Re-Order Plugin ?

March 24, 2017 by SNK

reoder posts within a category in wordpress

In this tutorial, we will see how can we reorder post within categories in WordPress. Sometime we may want to create series in the category, in that time it becomes essential to  change post order in WordPress.

There is no need to search for WordPress post order plugin to do this. We can easily do it by using simple piece of code. I have break them in easy steps below :-

lets get started  :-

What we are going to do ?

  • Find the categories id of the post you want to order.
  • Write the piece of code in functions.php to change the order of post in that category.

Step 1 : (Finding the ID of categories)

To find the id of the categories in the wordpress. Go to WordPress admin panel and go to Posts >  Categories and find the name of categories that you want to find id.

Hover over to it and click on edit and take a notice of url in the browser for id. Your categories will be in the format wp-admin/term.php?taxonomy=category&tag_ID=6&post_type=post.

wordpress post reorder category id

In above image is 6 is the categories id that you want to reorder. Take a note of it and open your functions.php by going to appearance > editor > functions.php

 

Step 2 : Add wordpress post order code in functions.php

Add these lines of code in your functions.php

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* Reverse Post Order for Post Archives */
add_action( 'pre_get_posts', 'cih_custom_post_order' );
 
function cih_custom_post_order( $arg) {
if ( is_admin() )
return;
//Query to Change Archives
if ( $arg->is_main_query() && is_archive() && !is_post_type_archive() && is_category() ) {
$arg->set( 'orderby', 'date' ); // this orders by date
$arg->set( 'order', 'ASC' ); // Changes the order to ascending order
        $arg->set( 'cat', '6' ); // Add your categories id here
}
}

Thats it,  its very easy. If you have any problem you can look the fix at WordPress codex and try to sort out yourself as well, else you can mention it via comments.

SHARE ON
Buffer

Enjoyed this article?

Like us on

WordPress change post order wordpress wordpress reorder posts within the category wordpress sort posts by date

Avatar for SNK

About SNK

Hello Welcome to my Blog. I develop Websites Using Laravel Framwork & WordPress. Get Latest updates on Facebook | Twitter

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get Connected !! With Us

TOP POSTS

  • How to Setup Spring MVC Project From Scratch in Intellij IDEA ?
  • Spring Configuration Class in JAVA [Class VS XML Config]
  • Annotations Based Configuration in Spring Framework
  • How to Configure Spring Framework with XML Configurations?
  • How to Remove Project Name from URL in JSP Project in Intellij IDEA ?

TUTORIALS TILL DATE

  • September 2022 (6)
  • June 2021 (7)
  • October 2020 (5)
  • September 2020 (6)
  • September 2018 (14)
  • August 2018 (3)
  • July 2018 (4)
  • March 2018 (8)
  • February 2018 (5)
  • January 2018 (1)
  • December 2017 (2)
  • August 2017 (8)
  • May 2017 (1)
  • April 2017 (1)
  • March 2017 (4)
  • February 2017 (3)
  • January 2017 (4)

CATEGORIES

  • Angular (2)
  • CSS3 (3)
  • D3 (3)
  • HTML5 (7)
  • JAVA (11)
  • Javascript (20)
  • jQuery (8)
  • Laravel (35)
  • Others (3)
  • PHP (11)
  • Spring (2)
  • WordPress (10)

Top Categories

  • Angular
  • CSS3
  • D3
  • HTML5
  • JAVA
  • Javascript
  • jQuery
  • Laravel
  • Others
  • PHP
  • Spring
  • WordPress

Get in Touch

DMCA.com Protection Status

Recent Articles

  • How to Setup Spring MVC Project From Scratch in Intellij IDEA ?
  • Spring Configuration Class in JAVA [Class VS XML Config]
  • Annotations Based Configuration in Spring Framework
  • How to Configure Spring Framework with XML Configurations?
  • How to Remove Project Name from URL in JSP Project in Intellij IDEA ?

© 2012-22 CodeIn House.  •  All Rights Reserved.