Order posts by date or keyword

I want to enable website visitors to order WordPress posts on the category page by date posted or by search keyword, similarly to how it's done on this page:

http://www.steinwaymusical.com/news.php

I'd appreciate a plugin recommendation or any other suggestion from knowledgeable people.

Thank you in advance!

Answers


WordPress has order and orderby options you can use in the query.

https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

<?php 
$args = array('order' => 'ASC', 'orderby' => 'name'); 
$query = new WP_Query($args);
while ( $query->have_posts() ) : $query->the_post(); 
// echo out the title, excerpt
endwhile; 
?> 

Your example page uses GET variables.

?selSort=name_asc&txtKeyword=sdfsdf

So you need to create a form with method="GET" that submit GET data to the current page. Then, using PHP, you can check if any GET data is set (in this case, selSort and txtKeyword). If either of those are set, put them into your query. Then you can modify the query to resemble this:

 <?php 
    $args = array('order' => $_GET['selSort'], 'orderby' => $_GET['txtKeyword']); 
    $query = new WP_Query($args);
    while ( $query->have_posts() ) : $query->the_post(); 
    // echo out the title, excerpt
    endwhile; 
    ?> 

Need Your Help

Experiences Using ASP.NET MVC Framework

.net asp.net asp.net-mvc

I am wondering what experiences people are having using the ASP.NET MVC Framework? In particular I am looking for feedback on the type of experience folks are having using the framework.

Self-joined data to hierarchical XML

sql-server xml recursive-query

I have a table in SQL Server 2012 with self-joined data like this:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.