Created
July 22, 2013 06:00
-
-
Save WenLiangTseng/6051591 to your computer and use it in GitHub Desktop.
wordpress-改變query
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_action( 'pre_get_posts', 'foo_modify_query_exclude_category' ); | |
| function foo_modify_query_exclude_category( $query ) { | |
| if ( ! is_admin() && is_main_query() && ! $query->get( 'cat' ) ) | |
| $query->set( 'cat', '-5' ); | |
| } | |
| //簡單寫法 | |
| add_action( 'pre_get_posts', 'foo_modify_query_exclude_category' ); | |
| function foo_modify_query_exclude_category( $query ) { | |
| $query->set( 'cat', '-5' ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment