Title: Theme Function: Posts per page, &amp; category exclude.
Last modified: August 20, 2016

---

# Theme Function: Posts per page, & category exclude.

 *  [Ashley Michèlle](https://wordpress.org/support/users/ashleymichelle/)
 * (@ashleymichelle)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/theme-function-posts-per-page-category-exclude/)
 * Hello!
 * I am having an issue getting my categories to be effectively hidden from the 
   home page…
 * I’m not sure why the code isn’t working, but I think I might possibly have some
   coding conflict.
 * in my Theme Functions, I have the following:
 *     ```
       function limit_posts_per_page() {
       	if ( is_home() )
       		return 9;
       	else
       		return 99; // default: 99 posts per page
       }
       ```
   
 * And also:
 *     ```
       add_filter('pre_option_posts_per_page', 'limit_posts_per_page');
       function limit_posts_per_archive_page() {
       	if ( is_category() )
       		set_query_var('posts_per_archive_page', 99); // or use variable key: posts_per_page
       }
       add_filter('pre_get_posts', 'limit_posts_per_archive_page');
   
       function my_home_query( $query ) {
         // not an admin page and is the main query
         if (!is_admin() && $query->is_main_query()){
           if(is_home()){
            //cat=-94, -158"."&posts_per_page=9
             $query->set('cat', -94, -158);
             $query->set('posts_per_page', 9);
           }
         }
       }
       add_action( 'pre_get_posts', 'my_home_query'
       );
       ```
   
 * If anyone could help me with this, it would be greatly appreciated!
 * Thank you in advance!

Viewing 1 replies (of 1 total)

 *  Thread Starter [Ashley Michèlle](https://wordpress.org/support/users/ashleymichelle/)
 * (@ashleymichelle)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/theme-function-posts-per-page-category-exclude/#post-2949026)
 * P.S. I am trying to utilize this on post that belong to more than one category,
   I might add. I understand there are some issues associated with this?

Viewing 1 replies (of 1 total)

The topic ‘Theme Function: Posts per page, & category exclude.’ is closed to new
replies.

## Tags

 * [category exclude](https://wordpress.org/support/topic-tag/category-exclude/)
 * [exclude](https://wordpress.org/support/topic-tag/exclude/)
 * [exclude category](https://wordpress.org/support/topic-tag/exclude-category/)
 * [function](https://wordpress.org/support/topic-tag/function/)
 * [post per page](https://wordpress.org/support/topic-tag/post-per-page/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [theme function](https://wordpress.org/support/topic-tag/theme-function/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Ashley Michèlle](https://wordpress.org/support/users/ashleymichelle/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/theme-function-posts-per-page-category-exclude/#post-2949026)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
