Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created October 13, 2011 19:40
Show Gist options
  • Save billerickson/1285290 to your computer and use it in GitHub Desktop.
Save billerickson/1285290 to your computer and use it in GitHub Desktop.
rewrite endpoints
<?php
/**
* Blog Rewrite Endpoint
* Used for filtering blog posts. Ex: most comments
*
* @since 1.0
*/
function be_add_blog_rewrite_endpoint() {
add_rewrite_endpoint( 'filter', EP_ALL );
}
add_action( 'init', 'be_add_blog_rewrite_endpoint' );
/**
* Blog Filters
* If using the 'filter' rewrite endpoint, modify the blog query
*
* @since 1.0
* @param $query object
*/
function be_blog_filters( $query ) {
global $wp_the_query;
if( $query === $wp_the_query && 'comments' == get_query_var( 'filter' ) )
$query->set( 'orderby', 'comment_count' );
}
add_action( 'pre_get_posts', 'be_blog_filters' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment