Advertisement
gqevu6bsiz

WP Hide Category edit code

Feb 28th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. function wp_hide_category( $query ) {
  2.  
  3. if( ! is_admin() && $query->is_main_query() ) {
  4. $wp_hide_category_hide_place = get_option( 'wp_hide_category_hide_place' );
  5. $category_hide = explode( ',', get_option('wp_hide_category_id') );
  6.  
  7. if( !empty( $wp_hide_category_hide_place ) ) {
  8. foreach( $wp_hide_category_hide_place as $template_name ){
  9. $call_name = 'is_' . $template_name;
  10. if( $query->$call_name() ){
  11.  
  12. if( !empty( $category_hide ) ) {
  13. foreach( $category_hide as $cat_id ) {
  14. $query->set( 'cat', '-' . $cat_id );
  15. }
  16. }
  17.  
  18. }
  19. }
  20. }
  21.  
  22. }
  23. }
  24. add_action('pre_get_posts' , 'wp_hide_category');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement