• I have 2 different sections in my agenda, featured events and normal events, featured events have a custom field called “promovido” now, for the normal events I want to exclude these featured events, here’s the query for normal events.

    <?php
    $today = date_i18n( 'F d');
    $agenda_query = new WP_Query(
    	array ( 'post_type' => 'agenda_posts',
    	 'posts_per_page' => '4',
    	 'orderby' => 'meta_value',
    	 'meta_key' =>  'evento_fecha',
    	 'order' => 'ASC',
    	 	'meta_query' => array(
    		array(
    		'key' => 'evento_fecha',
    		'meta-value' => $value,
    		'value' => $today,
    		'compare' => '>=',
    		'type' => 'CHAR',
    		))
    		)
    	); 
    
    ?>

    I’d like to exlude posts that have “promovidos” custom field.
    Is there a way to achieve this?

    Thanks in advance!

Viewing 1 replies (of 1 total)
  • Thread Starter AdrianPB

    (@adrianpb)

    I tried this, but it still doesnt work.

    <?php
    $today = date_i18n( 'F d');
    $agenda_query = new WP_Query(
    	array ( 'post_type' => 'agenda_posts',
    	 'posts_per_page' => '4',
    	 'orderby' => 'meta_value',
    	 'meta_key' =>  'evento_fecha',
    	 'order' => 'ASC',
    	 	'meta_query' => array(
    		'relation' => 'OR',
    		array(
    		'key' => 'evento_fecha',
    		'meta-value' => $value,
    		'value' => $today,
    		'compare' => '>=',
    		'type' => 'CHAR',
    		),
    		array(
                'key' => 'promovido',
                'value' => 'NOT EXISTS',
            )
    		)
    
    		)
    	); 
    
    ?>

    It says “Sorry, no posts match your criteria”
    Any help would be appreciated!

Viewing 1 replies (of 1 total)

The topic ‘Exclude posts with a certain meta_key’ is closed to new replies.