Last active
August 29, 2015 14:00
-
-
Save wpsmith/11144585 to your computer and use it in GitHub Desktop.
PHP: Use page_template within pre_get_posts
This file contains hidden or 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 | |
| add_filter( 'pre_get_posts', 'wps_archive_query' ); | |
| /** | |
| * Add more query args based on selected page template. | |
| * | |
| * @since 1.0.0 | |
| * | |
| * @param <type> $query | |
| * | |
| * @return <type> | |
| */ | |
| function wps_archive_query( $query ) { | |
| if ( is_page() ) { | |
| if ( 'page-stats.php' == get_page_template_slug( $query->queried_object_id ) ) { | |
| $query->set( 'post_date', date( 'Y-m-d', strtotime( '-30 days' ) ) ); | |
| $query->set( 'post_type', 'my_cpt' ); | |
| $query->set( 'orderby', 'comment_count' ); | |
| $query->set( 'order', 'ASC' ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment