Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
<?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.

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

share|improve this question

2 Answers 2

You have to explicitly set 'suppress_filters' => false in get_posts, otherwise filters are not applied.

share|improve this answer
    
after i try to succeed. How about question no 2 ? –  Agusto Nice Jul 14 '12 at 4:31
    
maybe others can help , question no 2? –  Agusto Nice Jul 18 '12 at 4:55

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...
?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.