对使用对帖子执行SQL查询LIKE \'x%\'
, 哪里x
这是你的信。
下面是一个简单的示例:
global $wpdb, $post;
$letter = \'a\'; // or $_GET[\'letter\']...
$query = "SELECT * FROM {$wpdb->posts} WHERE post_name LIKE %s";
$query = $wpdb->prepare($query, $letter.\'%\');
$results = $wpdb->get_results($query);
// note that variable name must be $post,
// because you need to override stupid wp globals...
foreach($results as $post){
setup_postdata($post);
// the usual loop functions go here
the_title();
}
wp_reset_postdata();