{"id":549,"date":"2014-01-01T03:03:20","date_gmt":"2014-01-01T03:03:20","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=549"},"modified":"2014-01-01T03:03:20","modified_gmt":"2014-01-01T03:03:20","slug":"how-to-sort-wordpress-posts-by-modified-date","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/how-to-sort-wordpress-posts-by-modified-date\/","title":{"rendered":"How to Sort WordPress Posts by Modified Date"},"content":{"rendered":"<p>To sort Word Press posts by post modified date and time. You may need this to show posts that have recently updated or some other reason to sort this way. Word Press provide query_posts function to change order of blog posts in several ways. This function support lot of parameter to customize posts listing. First, i am writing about parameter required to sort post and then talk about other parameter available to use with query_posts function.<\/p>\n<p><strong>How to Use<\/strong><\/p>\n<ul>\n<li>Open required theme files using ftp(recommended) or theme editor in which you want to sort posts list by modified date. For example:\u00a0<strong>index.php<\/strong>\u00a0for home page posts listing,\u00a0<strong>category.php<\/strong>\u00a0for category posts listing and\u00a0<strong>archive.php<\/strong>\u00a0for archive page listing. Do the same for any other customized post listing pages.<\/li>\n<li>Add\u00a0<strong>query_posts<\/strong>\u00a0function just above loop with\u00a0<strong>orderby=modified<\/strong>\u00a0parameter. If\u00a0<strong>query_posts<\/strong>\u00a0parameter is already there just append\u00a0<strong>orderby=modified\u00a0<\/strong>parameter at the end of parameter list. see example below.\n<pre><code>global $query_string;\r\n$posts=query_posts($query_string . '&amp;orderby=modified'); \r\nif (have_posts()) : while (have_posts()) : the_post();<\/code><\/pre>\n<\/li>\n<li>This code will not work for\u00a0next\u00a0pages 2,3,4\u2026 because we are not passing page number here. You don\u2019t need to pass page number if you are only showing limited posts in sidebar or some other special area. To fix this issue for normal posts listing simply grab page number value and pass it to function. Check code below.\n<pre><code>global $query_string;\r\n<strong><em>$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;<\/em><\/strong>\r\nquery_posts($query_string . '&amp;orderby=modified<strong>&amp;paged='.$paged<\/strong>);\r\n<\/code><\/pre>\n<\/li>\n<li>You may also use\u00a0<strong>order=ASC<\/strong>\u00a0or\u00a0<strong>order=DESC<\/strong>\u00a0to sort posts in ascending or descending order.<\/li>\n<li>orderby accept following values if you want to order by some other fields. values are: id, author, title, date, parent, rand, comment_count, menu_order, meta_value, meta_value_num<\/li>\n<\/ul>\n<p><strong>Other Customization<\/strong><\/p>\n<p>You can customize according to your need with several other parameter available. This section will list down some of useful parameters.<\/p>\n<ul>\n<li>posts_per_page \u2013 accept integer to show number of posts per page.<\/li>\n<li>tag \u2013 accept tag name as string to show posts lists from certain tag.<\/li>\n<li>order \u2013 accept ASC or DESC parameter to sort posts in ascending or descending order.<\/li>\n<li>cat \u2013 accept integer with minus or without minus sign. without minus sign represent plus which mean include posts from specified categories and minus sign means exclude posts from specified categories. You may use multiple categories with comma.<\/li>\n<li>category_name \u2013 Useful if you want to use category name instead of category number.<\/li>\n<li>year \u2013 accept numeric 4 digit year.<\/li>\n<li>monthnum \u2013 accept numeric month number. You may use year parameter along-with monthnum to show posts from certain month in a year.<\/li>\n<li>category__and \u2013 accept more then one category number in array and include posts that associated with all specified categories.<\/li>\n<li>category__in \u2013 accept more then one category number in array and include posts from either categories. This does not include posts from subcategories.<\/li>\n<li>category__not_in \u2013 accept more then one category number in array and exclude from either categories.<\/li>\n<li>post_type \u2013 accept post type like page, post,\u00a0attachment\u00a0or custom taxonomy.<\/li>\n<li>post__in \u2013 accept more then one post number in array and include only those posts.<\/li>\n<li>author \u2013 accept numeric integer parameter. Use multiple author ids with comma to include posts from multiple authors. minus sign can be used to exclude certain author posts.<\/li>\n<li>author_name \u2013 accept string parameter as author name.<\/li>\n<li>post_status \u2013 retrieves posts by post status. possible values are publish,pending,draft,auto-draft,future,private,inherit,trash. default value is publish.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>To sort Word Press posts by post modified date and time. You may need this to show posts that have recently updated or some other reason to sort this way. Word Press provide query_posts function to change order of blog posts in several ways. This function support lot of parameter to customize posts listing. First, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/549"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=549"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/549\/revisions"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}