Created
October 13, 2011 19:40
-
-
Save billerickson/1285290 to your computer and use it in GitHub Desktop.
rewrite endpoints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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