wordpress - Order posts by date or keyword -
i want enable website visitors order wordpress posts on category page date posted or search keyword, how it's done on page:
http://www.steinwaymusical.com/news.php
i'd appreciate plugin recommendation or other suggestion knowledgeable people.
thank in advance!
wordpress has order , orderby options can use in 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 title, excerpt endwhile; ?>
your example page uses variables.
?selsort=name_asc&txtkeyword=sdfsdf
so need create form method="get" submit data current page. then, using php, can check if data set (in case, selsort , txtkeyword). if either of set, put them query. can modify query 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 title, excerpt endwhile; ?>
Comments
Post a Comment