我正在尝试查询自定义帖子类型,该类型会在特定标题后按字母顺序搜索下3个帖子。 wp_query()
的参数片段是
$vars = array('paged' => $page, 'posts_per_page' => intval($posts),
'order' => 'asc', 'offset' => ($offset ? $offset : ''), 'orderby' => 'title' );
但不知道如何查询标题>的帖子具体标题。
答案 0 :(得分:1)
您可以使用posts_where
过滤器修改WP_Query
//create function to handle where clause change
function add_title_clause($where) {
$titleParam = 'C'; //change it according to your needs
return $where . " AND post_title > '" . $titleParam . "'";
}
//attach your function to the posts_where filter
add_filter( 'posts_where' , 'add_title_clause' );
$vars = array('paged' => $page, 'posts_per_page' => intval($posts),
'order' => 'asc', 'offset' => ($offset ? $offset : ''), 'orderby' => 'title' );
$results = new WP_Query($vars);
//remove filter so it does not affect other queries in same request
remove_filter( 'posts_where' , 'add_title_clause' );