Support » Fixing WordPress » Using 'category__and' returns no results in WordPress 3.2

  • Resolved drale2k

    (@drale2k)


    Hi,

    since i updated to WP 3.2 there seems to be a bug in using ‘category__and’.

    My values for the ‘category__and’ array are coming from 2 Dropdowns, so they may be selected but DON`T NEED TO.

    Example:

    $media_type = ( isset($_GET['media_type'])) ? get_category_by_slug($_GET['media_type']) : '';
    $country = ( isset($_GET['country'])) ? get_category_by_slug($_GET['country']) : '';
    
    $args = array(
          'category__and' => array($media_type->term_id,$country->term_id),
            'category__in' => array(8),
    	'paged' => $paged,
    	'monthnum' => $release_month,
    	'year'=> $release_year
    );
    
    	query_posts($args);

    The above code is the one i am using and which worked prior to WP 3.2.

    When both, $media_type and $country are selected through the dropdown it works.

    <strong>Problem:</strong>

    If none or only 1 of the two were selected it does not work. So it seems like they both need to be integers or it won`t work.

    I tried deactivating all plugins but it did not work. I need help since i don`t think i can solve this.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter drale2k

    (@drale2k)

    No one else has this issue? I will need to downgrade to 3.1 i guess ;/

    Thread Starter drale2k

    (@drale2k)

    Installing WordPress 3.1 did solve the issue so it is definitely a prob with 3.2, but i really would like to use the new version.

    Thread Starter drale2k

    (@drale2k)

    UPDATE://

    I have managed to fix it using this modified code

    $media_type = ( isset($_GET['media_type'])) ? get_category_by_slug($_GET['media_type']) : '';
    	$country = ( isset($_GET['country'])) ? get_category_by_slug($_GET['country']) : '';
    
    	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    	$filter = array(
    		$media_type->term_id,
    		$country->term_id
    	);
    
    	// remove false, null and empty values (category__and needs clean values)
    	$filter = array_filter($filter);
    
    	$args = array(
    		'category__and' => $filter,
    		'category__in' => array(8),
    		'paged' => $paged,
    		'monthnum' => $release_months,
    		'year'=> $release_years
    	);
    
    	query_posts($args);

    Although i am sure that ‘category__and’, prior to WP 3.2, would check for invalid array values and remove it by itself.

    However, i am happy to fixed this after many hours of try and error ;/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using 'category__and' returns no results in WordPress 3.2’ is closed to new replies.