使用WP_Query()查询新帖子,在WHERE过滤器中使用帖子ID?

我想知道是否可以使用WP_Query(get_posts等)返回ID大于提供的ID的帖子。

我已经遍历了WordPress Codex, 并且即使没有自定义查询也可能错过任何与帖子ID相关的帖子的查询。

由于似乎无法通过参数传递它, 因此我尝试编写一种方法来修改posts_where过滤器, 但似乎也不起作用。

add_filter( 'posts_where', 'filter_since_id');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    // Do Stuff
endwhile;
remove_filter('posts_where' , 'filter_since_id');

function filter_since_id($where = ''){
    $where .= " AND ID > 3'";
    return $where;
}

#1


澄清, 以便经过的人可以抓住并走:

add_filter( 'posts_where', 'filter_since_id');

function filter_since_id($where = ''){
    $where .= " AND ID > 3";
    return $where;
}

来源:

https://www.srcmini02.com/67520.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_40015.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?