Support

Account

Home Forums General Issues Numberposts & Meta Query Not Working Reply To: Numberposts & Meta Query Not Working

  • To clarify further, the whole code snippet is as follows:

      $relatedCat = get_field('service_related_industry');
         $args = array (
    		'posts_per_page' => 3,
                    'post_type' => 'case_study',
    		'meta_query' => array(
    			array(
            		'key' => 'cs_industry',
    				'value' => $relatedCat,
    				'compare' => 'LIKE',
    				)
    			),
    		'orderby' => 'DESC',
          );
    	 if (!$relatedCat) { 
    		 $relatedCat = get_field('service_related_category');
    		 unset ($args);
         	 $args = array (
            	'posts_per_page' => 3,
            	'cat' => $relatedCat,
            	'orderby' => 'DESC',
          	 );
    	 }
    

    If I comment out the first line, the IF statement works perfectly, and in fact it also adjusts the number of posts correctly. So, I reckon the problem is in the way the first field (service_related_industry) is being handled. But I can’t quite figure out what’s going wrong.