2016-12-29 97 views
2

我想显示包含数字的所有帖子。wordpress查询以数字开头的所有帖子

我使用这个代码:

global $wpdb; 
$postids = $wpdb->get_col($wpdb->prepare(" 
SELECT  ID 
FROM  $wpdb->posts 
WHERE  SUBSTR($wpdb->posts.post_title,1,1) = %s 
ORDER BY $wpdb->posts.post_title",REGEXP ^[0-9])); 
if ($postids) { 
$args=array(
    'post__in' => $postids, 
    'post_type' => 'shows', 
    'post_status' => 'publish', 
    'posts_per_page' => -1, 
    'caller_get_posts'=> 1 
); 
$my_query = null; 
$my_query = new WP_Query($args); 
if($my_query->have_posts()) { 
echo 'List of Posts Titles beginning with the letter '. $_GET['letter']; 
    while ($my_query->have_posts()) : $my_query->the_post(); ?> 
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> 
    <?php 
    endwhile; 
} 
wp_reset_query(); 
} 

我都试过,但它不工作只是1篇文章,但是当我将其更改为显示该用它显示所有的人都开始例如职位。

RLIKE ^[0-9] [0-9]%   

谢谢。

回答

0

为了只获取记录开始数,使用REGEXP

SELECT  ID 
FROM  $wpdb->posts 
WHERE  $wpdb->posts.post_title REGEXP '^[0-9]+' 
ORDER BY $wpdb->posts.post_title; 
+0

完美过滤它们谢谢 – ANto1

相关问题