0

I have mainly protected categories, but I have one open category, how can I set it up so I load only the open catgeory posts to show on my home page

  • WE NEED MOAR INFORMATIONZ - how are you protecting categories? A plugin? Which one? Are you using a public theme or your own? – TheDeadMedic Jan 13 '12 at 22:55
  • I'm using the UAM to protect the categories and the theme is Third Style 1.1.1 – Jonnny Jan 13 '12 at 22:56
0

This should about do it for you, add args as needed

$args = array(
    //basic post data
    'posts_per_page' => 10,
    'post_type'      => 'post',
    'post_status'    => 'publish',
    //category
    'category_name'  => 'your-cat-slug'
);
$posts = new WP_Query( $args );

Docs: WP_Query

  • Thank you, does this go in the loop.php file? – Jonnny Jan 13 '12 at 23:22
  • Really depends on your setup...loop.php isn't even a default file, so you'll have to figure that out on your own, but I would guess it does. The Loop documentation should help you out. – mor7ifer Jan 13 '12 at 23:46
2

It would be better to filter the query on the home page instead of adding another one with WP_Query

add_filter( 'pre_get_posts', 'my_home_query' );
function my_home_query( $query ) {
 if( $query->is_home ) {
       $query->set( 'cat', $cat_id );
   }
     return $query;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.