php - Wordpress query_posts returns post from unspecified categories -
i trying retrieve post category using query_posts returns post unspecified category other parameters such sort , showposts works fine.
extract(shortcode_atts(array( 'categories' => 'partners', 'imageswidth' => '200px', 'imagesheight' => '115px', 'imageslink' => 'web_link', 'partnerscount' => 'all', 'columnscount' => 1, 'imagescrop' => 'no', 'imagesblackhovercolor' => 'no', 'imagesopacity' => 100, 'imagesgrayscale' => 'no', 'imagescolorize' => '', 'imagesnegative' => 'no', 'imagessort' => 'date asc' ), $atts)); //$args = "category_name=".categories; //$catids = get_cat_id( $cat_name='partners' ); $args = "cat_name=".categories; $args .= strtolower($partnerscount) != "all" ? "&showposts=".$partnerscount : ''; $args .= $imagessort == "date_asc" ? "&orderby=date&order=asc" : ''; $args .= $imagessort == "date_dsc" ? "&orderby=date&order=desc" : ''; $args .= $imagessort == "random" ? "&orderby=rand" : ''; query_posts($args); while ( have_posts() ) : the_post(); { $output = $output.get_the_title(); }
according wordpress documents (http://codex.wordpress.org/class_reference/wp_query#category_parameters)
in order show posts category can use next parameters:
cat (int) - use category id.
category_name (string) - use category slug (not name).
category__and (array) - use category id.
category__in (array) - use category id.
category__not_in (array) - use category id.
the right parameter is: category_name
, not cat_name
. replacing:
$args = "cat_name=".categories;
with:
$args = "category_name=".$categories;
while partners
slug
of category, should solve problem.
edit 1:
please notice , wrote categories
without $ sign. php treats defined , not variable. try line: $args = "category_name=".$categories;
edit 2: if can't fetch slug of category, try getting id of name.
$catid = get_cat_id( $categories ); $args = "cat=".$catid;
Comments
Post a Comment