Wordpress - Use wp_query in category archive - how to display the appropriate category? Wordpress - Use wp_query in category archive - how to display the appropriate category? wordpress wordpress

Wordpress - Use wp_query in category archive - how to display the appropriate category?


Well, this is the best solution I could come up with on my own (using single_cat_title to set the variable):

$currentCategory = single_cat_title("", false);$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;$query = array(    'category_name' => $currentCategory,    'paged'=> $paged,    'posts_per_page' => '15');$pageposts = new WP_Query($query);


I realize this is old, but I had the same problem. I used a method similar to what you came up with for my category archive, but I needed to use WP Query for search.php as well, which led me to looking for a solution. The wordpress codex has a way to preserve the original query for search, and it seems to work for a category archive as well:

<?phpglobal $query_string;$query_args = explode("&", $query_string);$search_query = array();foreach($query_args as $key => $string) {    $query_split = explode("=", $string);    $search_query[$query_split[0]] = urldecode($query_split[1]);} // foreach$search = new WP_Query($search_query);?>

http://codex.wordpress.org/Creating_a_Search_Page#Preserving_Search_Page_Results_and_Pagination

Should be able to just add the arguments you need and be good to go.