• I want to show the custom posts which date in the custom field (‘wpcf-vanaf-in-het-theater’) is before today.

    I can’t find out what I’m doing wrong. Everything looks ok, but when I change compare => from “<” to “>” there’s no post showing up.

    This is my code:

    <?php
    
    $today = date('Ymd');
    
    $args = array(
      	'post_type' => 'films',
      	'post_status' => 'publish',
      	'posts_per_page' => -1,
    	'meta_query' => array(
    	    array(
    	        'key' => 'wpcf-vanaf-in-het-theater',
    	        'compare' => '<',
    	        'value' => $today,
    	    )
    	)
    );
    
    $my_query = new WP_Query($args);
    
    if( $my_query->have_posts())
    	while ($my_query->have_posts()) : $my_query->the_post(); ?>
    		<p><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    		<?php
    		$vanafTheater = types_render_field("vanaf-in-het-theater", array("style"=>"text", "format"=>"Ymd"));
    		echo $vanafTheater . " vs ";
    		echo $today . "<br />";
      	endwhile;
    	wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Please help me!

  • The topic ‘Query date comparison with custom field’ is closed to new replies.