Home Forums Front-end Issues Filtering CPT with date picker custom field Reply To: Filtering CPT with date picker custom field

  • Hi Elliot,

    As you suggested, I’moved the $date formatting to be within the loop. I’m still pulling the wrong date for each post. For some reason it seems to be pulling the wrong date for each post. I have no idea where it’s getting this date from since none of the posts have this date. Below is my code and live link:

    remove_action('genesis_loop', 'genesis_do_loop');
    add_action('genesis_loop', 'custom_loop');
    function custom_loop() {  
    	// Intro Text (from page content)
    	echo '<div class="page hentry entry">';
    	echo '<h1 class="entry-title">'. get_the_title() .'</h1>';
    	echo '<div class="entry-content">' . get_the_content() ;
    	$args = array(
    		'post_type' => 'events', // enter your custom post type
    		'meta_key' => 'class_date', // name of custom field
    	    'orderby' => 'meta_value_num',
    	    'order' => 'ASC',
    	$loop = new WP_Query( $args );
    	if( $loop->have_posts() ):
    	while( $loop->have_posts() ): $loop->the_post(); global $post;
    		echo '<div id="events">';
    			echo '<h3>' . get_the_title() . '</h3>';
    				/* Create PHP DateTime object from Date Picker Value
        this example expects the value to be saved in the format: yymmdd (JS) = Ymd (PHP) */
        $date = DateTime::createFromFormat('yymmdd', get_field('class_date'));
    			echo '<p>' . date('F n Y') . '</p>';
    			echo '<p>'. get_field('time') . '</p>';
    			echo '<p>' . get_the_content() . '</p>';
            echo '</div>';
    /** Remove Post Info */