Use either:
<?php $the_query = new WP_Query ('posts_per_page=2&category_name=events'); ?>
or
<?php $the_query = new WP_Query(array(
'posts_per_page' => 2,
'category_name' => 'events', // this is the category SLUG
));
// EDIT
Please note that category_name
actually is the category slug (which is for one-word names originally the same). It is not the actual name (maybe having spaces, special characters etc. in it), though. In your case, where you just want to specifiy a certain category, you can do this either by means of the ID (cat=42
) or the slug (category_name=events
).
If you really want/have to use the name, you have to use get_cat_ID('Category Name')
, for instance like so:
$the_query ?>= new WP_Query(array(
'posts_per_page' => 2,
'cat' => get_cat_ID('Events'),
));