WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] This filter doesn't work (2 posts)

  1. alvarols
    Member
    Posted 1 year ago #

    I'm trying to use this code that I take from wordpress codex, but the filter is not taking effect.

    ` <?php
    function filter_where($where = '') {
    //posts in the last 24 Hours
    $where .= " AND post_date > '" . date('Y-m-d H:i:s', strtotime('-36 hours')) . "'";
    return $where;
    }
    add_filter('posts_where', 'filter_where');
    $query = new WP_Query("cat=".$categoria."");
    ?>
    <?php if(have_posts()) : ?><?php while($events_query->have_posts()) : $postnum = $postnum + 1; $events_query->the_post(); ?>
    <h1 class="negrocentro">"><?php the_title(); ?></h1>
    <?php endwhile; ?>
    <?php endif; ?>
    <?php
    remove_filter( 'posts_where', 'filter_where' );
    ?>

  2. alvarols
    Member
    Posted 1 year ago #

    Solved:

    `<?php
                                function filter_where($where = '') {
                                //posts in the last 24 Hours
                                $where .= " AND post_date > '" . date('Y-m-d H:i:s', strtotime('-36 hours')) . "'";
                                return $where;
                              }
                                add_filter('posts_where', 'filter_where');
                                $query = new WP_Query("cat=".$categoria."");
                            ?>
                            <?php if(have_posts()) : ?><?php while($events_query->have_posts()) : $postnum = $postnum + 1; $events_query->the_post(); ?>
                            <h1 class="negrocentro">"><?php the_title(); ?></h1>
                            <?php endwhile; ?>
                            <?php endif; ?>
                            <?php
                                remove_filter( 'posts_where', 'filter_where' );
                            ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags