wordpress - WP Query ignores variable for specific category -
ok i'm missing obvious here since it's simple thing, reason can't wp query work. want query posts category page user visiting (using get_the_category). -
$category = get_the_category(); $category_id = $category[0]->cat_id; $category_items = new wp_query( array( 'post_type' => 'post', 'cat' => $category_id, 'showposts' => -1, 'orderby' => 'rand' ) );
$category_id gives me correct id category page, referring inside wp query makes query posts regardless of category.
try this:
$category = get_the_category(); $category_name = $category[0]->cat_name; $category_items = new wp_query( array( 'post_type' => 'post', 'category_name' => $category_name, 'showposts' => -1, 'orderby' => 'rand' ) );
Comments
Post a Comment