{"id":11807,"date":"2011-01-15T19:04:46","date_gmt":"2011-01-15T19:04:46","guid":{"rendered":"https:\/\/wordpress.org\/plugins-wp\/sort-query-posts\/"},"modified":"2012-09-04T12:11:31","modified_gmt":"2012-09-04T12:11:31","slug":"sort-query-posts","status":"publish","type":"plugin","link":"https:\/\/pap-aw.wordpress.org\/plugins\/sort-query-posts\/","author":6813722,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"1.1","stable_tag":"1.1","tested":"3.4.2","requires":"2.5","requires_php":"","requires_plugins":"","header_name":"Sort Query Posts","header_author":"T\u00fabal Mart\u00edn","header_description":"","assets_banners_color":"","last_updated":"2012-09-04 12:11:31","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"http:\/\/wordpress.org\/extend\/plugins\/sort-query-posts","header_author_uri":"http:\/\/margenn.com","rating":5,"author_block_rating":0,"active_installs":100,"downloads":11934,"num_ratings":3,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","installation","changelog"],"tags":[],"upgrade_notice":[],"ratings":{"1":0,"2":0,"3":0,"4":0,"5":"3"},"assets_icons":[],"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.0","1.1"],"block_files":[],"assets_screenshots":[],"screenshots":[],"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[58424,86,1626,2286,4644],"plugin_category":[],"plugin_contributors":[79290],"plugin_business_model":[],"class_list":["post-11807","plugin","type-plugin","status-publish","hentry","plugin_tags-order_by","plugin_tags-post","plugin_tags-query","plugin_tags-reorder","plugin_tags-sort","plugin_contributors-tubal","plugin_committers-tubal"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/s.w.org\/plugins\/geopattern-icon\/sort-query-posts.svg","icon_2x":false,"generated":true},"screenshots":[],"raw_content":"<!--section=description-->\n<p>A really simple and lightweight plugin (73 lines of code - comments included) to sort posts on-the-fly without making a new query to the database (improves performance).<\/p>\n\n<h4>Features:<\/h4>\n\n<ul>\n<li>Supports <strong>all <code>order_by<\/code> and <code>order<\/code> values of the <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/query_posts#Orderby_Parameters\">query_posts function<\/a><\/strong> except <code>meta_value<\/code> and <code>meta_value_num<\/code> (which require a database query).<\/li>\n<li>Supports <strong>changing the order of all types of posts<\/strong>, including custom post type posts and custom post type \"archive\" posts.<\/li>\n<\/ul>\n\n<h4>Documentation<\/h4>\n\n<p>This plugin adds the function <code>sort_query_posts_by(string $order_by [, string $order])<\/code> to the global context.\nThe second <code>$order<\/code> parameter is optional. Its default value is <code>asc<\/code> (ascending order).<\/p>\n\n<p><strong>Call this function before <a href=\"http:\/\/codex.wordpress.org\/The_Loop\">the loop<\/a> to change how posts are ordered.<\/strong>\nAfter calling this function you can show the posts as you normally would.<\/p>\n\n<p>You can sort posts by:<\/p>\n\n<ul>\n<li>author<\/li>\n<li>comment_count<\/li>\n<li>date<\/li>\n<li>id<\/li>\n<li>menu_order<\/li>\n<li>modified<\/li>\n<li>parent<\/li>\n<li>title<\/li>\n<\/ul>\n\n<p>This is specially useful in two cases:<\/p>\n\n<ul>\n<li>When you need to reorder the posts returned by the query that Wordpress creates from your given URL. Custom post type \"archive\" posts are a great example of this case.<\/li>\n<li>When you need the posts returned by your customized query (e.g. <code>query_posts()<\/code>) to be shown more than once on the same page and ordered differently.<\/li>\n<\/ul>\n\n<p><strong>Examples:<\/strong><\/p>\n\n<pre><code>&lt;?php sort_query_posts_by('title', 'desc'); ?&gt;\n<\/code><\/pre>\n\n<p>The example above will sort posts by their title in descending order without making a new query to the database.\nThis way sorting is performance friendly.<\/p>\n\n<pre><code>&lt;?php sort_query_posts_by('ID'); ?&gt;\n<\/code><\/pre>\n\n<p>The example above will sort posts by their ID in ascending order.<\/p>\n\n<pre><code>&lt;?php sort_query_posts_by('rand'); ?&gt;\n<\/code><\/pre>\n\n<p>The example above will sort posts randomly. When sorting randomly <code>$order<\/code> is ignored.<\/p>\n\n<p>Plugin developed by T\u00fabal Mart\u00edn at <a href=\"http:\/\/www.margenn.com\">www.margenn.com<\/a>.<\/p>\n\n<!--section=installation-->\n<ol>\n<li>Upload <code>sort-query-posts<\/code> folder to the <code>\/wp-content\/plugins\/<\/code> directory<\/li>\n<li>Activate the plugin through the 'Plugins' menu in WordPress<\/li>\n<li>Use the added function <code>sort_query_posts_by<\/code> after any wordpress query and your posts will be sorted to your needs.<\/li>\n<\/ol>\n\n<!--section=changelog-->\n<h4>1.1<\/h4>\n\n<ul>\n<li>Code refactored for improved performance. Updating is recommended.<\/li>\n<\/ul>","raw_excerpt":"Sort posts on-the-fly without making a new SQL query","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/pap-aw.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/11807","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pap-aw.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/pap-aw.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/pap-aw.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=11807"}],"author":[{"embeddable":true,"href":"https:\/\/pap-aw.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/tubal"}],"wp:attachment":[{"href":"https:\/\/pap-aw.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=11807"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/pap-aw.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=11807"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/pap-aw.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=11807"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/pap-aw.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=11807"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/pap-aw.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=11807"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/pap-aw.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=11807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}