gpt4 book ai didi

php - wordpress查询所有以数字开头的帖子

转载 作者:行者123 更新时间:2023-11-29 03:22:38 25 4
gpt4 key购买 nike

我正在尝试显示所有包含数字的帖子。

我正在使用这段代码:

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 个帖子不起作用,但是当我将其更改为显示以 a 开头的示例帖子时,它会显示所有帖子。

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

谢谢。

最佳答案

要仅获取以数字开头的记录,请使用 REGEXP 过滤它们

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

关于php - wordpress查询所有以数字开头的帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41373551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com