我有一个食谱网站和搜索选项。现在我有食谱名称 CAKE ,当我搜索 CAKES 时,它没有显示结果。它很好用 CAKE 或 CAK 。我想要LIKE查询的结果。请帮帮我。
这是我的自定义搜索参数代码:
<?php $args = array( 'posts_per_page' => -1, 'post_type' => 'recipes', 's' => $_GET['s'] );
$myposts = get_posts( $args );
if ( empty( $myposts ) ) {
echo 'No results found in Recipe!';
} else { ?>
//show recipes
<?php wp_reset_postdata();
} ?>
答案 0 :(得分:0)
试试这个
$args = array('posts_per_page' => -1, 'post_type' => 'recipes','s' => $_GET['s']);
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
//whatever you want to do with each post
}
} else {
// no posts found
}
答案 1 :(得分:0)
$str = $_GET['s'];
$result = rtrim($str, 's');
$result_sing = str_pad($result, strlen($str) - 1, 's');
$args = array(
'posts_per_page' => -1,
'post_type' => 'recipes',
's' => $result_sing,
);