Support

Account

Home Forums General Issues WP_Query if field is populated Reply To: WP_Query if field is populated

  • Solved it. For anyone else wondering, this is how I did it:

    <?php 
    $args = array(
    	'numberposts' => -1,
    	'post_type' => 'portfolio',
    	'showposts' => 1,
    	'orderby' => 'rand',
    	'meta_query' => array(
    		'relation' => 'AND',
    		array(
    			'key'     => 'client_quote',
    			'value'   => '',
    			'compare' => '!='
    		)
    	)
    );
     
    $client_quote = new WP_Query( $args );
    ?>

    That randomly picks one post from the Portfolio custom post type, as long as the client_quote custom field contains some text.