你读过这篇帖子吗?Display all posts starting with given letter?
这可不简单WP_Query 这很不幸,因为这将有助于保持分页。
// Rules
$args = [\'post_type\'=>\'post\',\'orderby\'=>\'name\'];
// The Query
$query1 = new WP_Query( $args );
// The Loop
while ( $query1->have_posts() ) {
$query1->the_post();
echo \'<li>\' . get_the_title() . \'</li>\';
}
You could use wpdb
global $wpdb;
$results = $wpdb->get_results( "SELECT ID FROM wp_posts WHERE post_title LIKE \'B%\';", ARRAY_A );
&;然后使用WP\\u查询
// Rules
$args = [\'post_type\'=>\'post\',\'post__in\'=>$results];
// The Query
$query1 = new WP_Query( $args );
// The Loop
while ( $query1->have_posts() ) {
$query1->the_post();
echo \'<li>\' . get_the_title() . \'</li>\';
}
pre_get_posts()
是做这种事情的另一个好方法。