WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Post query displaying posts that meet 2 or more conditions (2 posts)

  1. ameraz
    Member
    Posted 1 year ago #

    I want to query posts that belong to a certain category and that have a specific meta_key to display a slider banner in archive pages.

    So far I have this ...

    if ( is_post_type_archive() ) {
    	$catid = get_query_var('cat');
    	query_posts(array(
    		'meta_key'=>'home-banner',
    		'posts_per_page'=>'3',
    		'cat'=>$catid
    	));
    }

    ... but it displays posts belonging to 'cat'=>$catid no matter if the 'meta_key'=>'home-banner' is present ...

    Any help will be very much appreciated!!
    Thanks in advance.

  2. ameraz
    Member
    Posted 1 year ago #

    damn!!!

    the answer was so simple...

    I was all right in the first place, the conditional was mistaken...

    if ( is_archive() ) {
    query_posts(array(
    	'meta_key'=> 'home-banner',
    	'posts_per_page' => '3',
    	'cat' => $catid
    ));

Topic Closed

This topic has been closed to new replies.

About this Topic