0

I am using an option framework. This saves catagory ids.To get ids I have done

$cat = $atts['post_catagory'];
var_dump($cat);

The var dump result is

array (size=2) 0 => string '1' (length=1) 1 => string '15' (length=2)

Here 1 and 15 are catagory ids. To query posts I have used

$args = array( 'orderby'=> ASC,'cat'=>$cat);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post );
the_title( '<h2 class="entry-title"><a href="' . get_permalink() . '"   
title="'.the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' );
endforeach;

But I got error. Also can do the same query using wp_query? Thanks

0

cat needs to be an int or string, and you are passing an array. Either use category__in instead, which accepts an array, or convert $cat to a string of values with implode(',', $cat)

  • Works like a charm – ashraf Mar 19 '15 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.