Function to only display posts of a certain category on the posts home page
authorLaury GvR <laury@gaslightmedia.com>
Mon, 23 May 2016 20:23:14 +0000 (16:23 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Mon, 23 May 2016 20:23:14 +0000 (16:23 -0400)
functions.php

index adf378a..c4b6b22 100644 (file)
@@ -118,6 +118,17 @@ function glm_get_header() {
 //    echo '</div>';
 
 
+/**
+ * This function will ensure only the posts from a certain category will display
+ * on the blog/post home page.
+ */
+function my_home_category( $query ) { 
+    if ( $query->is_home() && $query->is_main_query() ) { 
+        $query->set( 'cat', '29');  
+    }    
+} 
+add_action( 'pre_get_posts', 'my_home_category' );
+
 /**
  * glm_side_menu
  *