Update Posts Order on Click

Help visitors sort content on your website by adding filtering options to your Posts.

WP Popular Posts Plugin plugin used in the below example in order to add support for filtering Most Popular items (determined by number of views).

Place in the home.php template or whatever template being used for the Posts or Custom Post Type feed.

HTML Filters

<p>SORT BY:</p>
	<li><a href="<?php echo get_permalink(18); ?>?dir=DESC">Newest to Oldest</a></li>
	<li><a href="<?php echo get_permalink(18); ?>?dir=ASC">Oldest to Newest</a></li>
	<li><a href="<?php echo get_permalink(18); ?>?dir=VIEWS">Most Popular</a></li>

PHP args to support filtering

$args = array(
	'order'    => (isset($_GET['dir']) ? $_GET['dir'] : 'ASC')
query_posts( $args );


WP Popular Posts Plugin

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.