Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress:WP_查询获取额外的帖子_Wordpress - Fatal编程技术网

WordPress:WP_查询获取额外的帖子

WordPress:WP_查询获取额外的帖子,wordpress,Wordpress,与wordpress有问题,使用WP_查询将过去五天内的最后三篇帖子拉到一个页面上 这是我的过滤器,我在这里设置了wp_query的新实例: <?php get_header(); function filter_where( $where = '' ) { $where .= " AND post_date > '" . date('Y-m-d', strtotime('-5 days')) . "'"; return $where; } $args =

与wordpress有问题,使用WP_查询将过去五天内的最后三篇帖子拉到一个页面上

这是我的过滤器,我在这里设置了wp_query的新实例:

<?php 

get_header(); 

function filter_where( $where = '' ) {
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-5 days')) . "'";
    return $where;
}

$args = array(
            'post_type' => 'post',
            'post_status' => 'publish',
            'posts_per_page' => '3'
            );

add_filter( 'posts_where', 'filter_where' );

$query = new WP_Query( $args ); 
?>

您应该在
函数中保留以下代码。php

function filter_where( $where = '' ) {
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-5 days')) . "'";
    return $where;
}
add_filter( 'posts_where', 'filter_where' );
以及页面模板文件中的以下代码

$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => '3'
);
$query = new WP_Query( $args );
while($query->have_posts()): $query->the_post();
    // ...
endwhile;
此外,要在特定页面上执行此操作,您应该在
filter\u中添加一个条件,其中
函数,即

if( is_page('page_slug') ) // or something like this
{
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-5 days')) . "'";
}
return $where;

.

您应该在
函数中保留以下代码。php

function filter_where( $where = '' ) {
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-5 days')) . "'";
    return $where;
}
add_filter( 'posts_where', 'filter_where' );
以及页面模板文件中的以下代码

$args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => '3'
);
$query = new WP_Query( $args );
while($query->have_posts()): $query->the_post();
    // ...
endwhile;
此外,要在特定页面上执行此操作,您应该在
filter\u中添加一个条件,其中
函数,即

if( is_page('page_slug') ) // or something like this
{
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-5 days')) . "'";
}
return $where;
.

我有完全相同的问题,并在上面的链接中找到了答案。问题是我把一篇文章弄得粘乎乎的,这意味着它总是会在我的搜索结果中被返回

将以下内容添加到我的查询中可停止此行为

'ignore_sticky_posts' => true
$post_query =  new WP_Query();
$query_args =  array( 'ignore_sticky_posts' => true, 'post__in' => array(123,124), 'posts_per_page'=> '-1', 'order'=> 'ASC' , 'orderby' => 'title');
$myposts    =  $post_query->query($query_args);

我有完全相同的问题,并在上面的链接中找到了答案。问题是我把一篇文章弄得粘乎乎的,这意味着它总是会在我的搜索结果中被返回

将以下内容添加到我的查询中可停止此行为

'ignore_sticky_posts' => true
$post_query =  new WP_Query();
$query_args =  array( 'ignore_sticky_posts' => true, 'post__in' => array(123,124), 'posts_per_page'=> '-1', 'order'=> 'ASC' , 'orderby' => 'title');
$myposts    =  $post_query->query($query_args);

感谢组织提示,但代码似乎仍在引入未指定的帖子。感谢组织提示,但代码似乎仍在引入未指定的帖子。