Get last post date yesterday from each categories not work & double result post

<?php
$categories1=get_categories('orderby=post_date&order=DESC');

function filter_where( $where = '' ) {
$today = date('Y-m-d', current_time( 'timestamp' ));
$yesterday = strtotime ( '-1 day' , strtotime ( $today ) ) ;
$yesterday = date('Y-m-d', $yesterday);
$where .= " AND post_date >= '" . $yesterday . "'" . " AND post_date < '" . $today . "'";
return $where;
} 
add_filter('posts_where', 'filter_where');

foreach($categories1 as $category1) {
$posts=get_posts('showposts=1&cat='. $category1->term_id);
if ($posts) { 
foreach($posts as $post) {
setup_postdata($post); 
?>
        <li> 
    <?php the_time('F j, Y , g:i a') ?>
    <h6></h6> 
    <h5 class="l_yellow"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h5>
</li>
<?php }}} 
remove_filter('posts_where', 'filter_where');
wp_reset_query();
?>

my question :

  1. Today date july 14 , why show up post from date july 11 ?
    I want get only date not time.

    Read More
  2. I have one post in two categories , how to show up only one post from one categories ?

Related posts

Leave a Reply

2 comments

  1. For your second question, something like the code sample below will add the post’s IDs to an array and not show them if they’re already in the array:

    <?php
    
    foreach($posts as $post) {
        setup_postdata($post); 
    
        $posts_array[] = get_the_ID();
    
        if ( ! in_array( get_the_ID(), $post_array ) ) {
    ?>
    <li> 
        <?php the_time('F j, Y , g:i a') ?>
        <h6></h6> 
        <h5 class="l_yellow"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h5>
    </li>
    <?php
        }
    
        // the rest of your code...
    ?>