例如,使用posts_where
滤器如果需要使用posts_clauses
过滤,然后交换$where
具有$pieces
和设置$pieces[\'where\'] .=
而不是$where .=
. 把它放到你的函数中。php文件,并在查询帖子之前添加一些条件标记。
function filter_where( $where )
{
// Add some conditionals and abort if they\'re not met:
// @example Abort on pages
if ( ! is_page() )
return;
// posts in the last 30 days
// $where .= " AND post_date > \'".date( \'Y-m-d\', strtotime( \'-30 days\' ) )."\'";
// posts 30 to 60 days old
// $where .= " AND post_date >= \'".date( \'Y-m-d\', strtotime( \'-60 days\' ) )."\'"." AND post_date <= \'".date( \'Y-m-d\', strtotime( \'-30 days\' ) )."\'";
// posts between 01.03.2012 and 21.03.2012
$where .= " AND post_date >= \'2012-03-01\' AND post_date <= \'2012-03-21\'";
return $where;
}
add_filter( \'posts_where\', \'filter_where\' );
<小时>
Edit: 这是OP的原始循环:
<section id="content">
<?php
query_posts( array( \'post_type\' => array( \'post\', \'twentyyearsago\' ) ) );
if ( have_posts() )
{
while ( have_posts() )
{
the_post();
if ( \'twentyyearsago\' === get_post_type() ) // FIX THIS: strict type checking with "==="
{
?>
<article class="twentyyears">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="This day 20 years ago">This day 20 years ago</a></h2>
<?php the_content(); ?>
<footer><?php the_time( \'F j, Y\' );?></footer> // FIX THIS: One leading "<" in front of "<?php" too much
</article>
<?php } else { ?>
<article class="post">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
<footer><?php the_time( \'F j, Y\' ); ?></footer>
</article>
<?php
} // FIX THIS: one trailing ";" too much
} // endwhile;
else
{
// do stuff
echo "No Posts.";
} // endif;
wp_reset_query();
?>
</section>