The variable $theTitle is not interpolated in a single quote string. query_posts('category_name=.$theTitle&orderby=rand'); Will ask for exactly that string. $theTitle will not be replaced with a title and the dot (.) will remain in the query. The result will be unpredictable. So, use a double quoted string: query_posts( "category_name={$theTitle}&orderby=rand" ); Or change the order of the arguments and concatenate the title. query_posts( 'orderby=rand&category_name=' . $theTitle ); Are you sure you want to use `query_posts()` in an assignment? Isn't kind of like telling the teacher you didn't read the [documentation][1] which pretty much says "don't use query_posts()". --- EDIT: Apparently, the query_posts() function uses the parameters for WP_Query which makes sense. [The instructions][2] say that you should use the category slug, not category name: `category_name (string) - use category slug (NOT name).` I have no idea why they would not name the paramteter `category_slug` So first we need to get the category slug. function wpse_100126_get_category_slug() { $current_cat = get_category( get_query_var( 'cat' ) ); return $current_cat->slug; } Then plug that into the query: query_posts( 'orderby=rand&category_name=' . get_category_slug() ); [1]: http://codex.wordpress.org/Function_Reference/query_posts [2]: http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters