• Resolved Joe Mac415

    (@joe-mac415)


    Hello,

    I am looking to query tomorrow’s posts stored in the client’s system. I can easily pull up the future posts using this:

    <?php
    
      function filter_where($where = '') {
    
        $where .= " AND post_date >= DATE( NOW() )";
    
        return $where;
    
      }
    
    	add_filter('posts_where', 'filter_where');
    
    	$my_query = new WP_Query( 
    
    		array( 
    
    			'post_type'=>'post', 
    
    			'orderby' => 'date',
    
    			'order' => 'DESC', 
    
    			'cat' =>348, 
    
    			'post_status' => 'future',
    
    			)
    
    		);
    
    	while ( $my_query->have_posts() ) :
    
    		$my_query->the_post();
    
    		$do_not_duplicate = $post->ID;
    
    ?>
    
    <p> <?php the_date(); ?></p> 
    
    <p><strong><?php $value = get_post_meta($post->ID, 'tba', true);
    
    	if($value == 'true') { ?>TBA<?php } else {the_time('g:i a');}; ?> - <a href="<?php echo get_post_meta($post->ID, "event_url", true); ?>"><?php the_title() ?></a></strong> 
    
    <?php 
    
    	endwhile;  
    
    remove_filter('posts_where', 'filter_where');
    
    ?>

    But I just want to have it post the next day’s posts and the next week’s. Can anyone help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Joe Mac415

    (@joe-mac415)

    Any help on this? I am on deadline here.

    Thread Starter Joe Mac415

    (@joe-mac415)

    Ok I got it. If anyone is wondering, you need to create $where between the two dates:

    $where .= " AND post_date >= '" . date('Y-m-d', strtotime('+1 day')) . "'" . " AND post_date <= '" . date('Y-m-d', strtotime('+7 days')) . "'";

    And it works.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Query Tomorrow's Posts’ is closed to new replies.