Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress搜索无法正常工作_Wordpress_Search - Fatal编程技术网

WordPress搜索无法正常工作

WordPress搜索无法正常工作,wordpress,search,Wordpress,Search,我有一个食谱网站和搜索选项。现在我有了配方名称蛋糕,当我搜索蛋糕时,它不会显示结果。用蛋糕或结块即可。我想要一个类似查询的结果。请帮帮我 以下是我的自定义搜索参数代码: <?php $args = array( 'posts_per_page' => -1, 'post_type' => 'recipes', 's' => $_GET['s'] ); $myposts = get_posts( $args ); if ( empty( $myposts ) ) {

我有一个食谱网站和搜索选项。现在我有了配方名称蛋糕,当我搜索蛋糕时,它不会显示结果。用蛋糕结块即可。我想要一个类似查询的结果。请帮帮我

以下是我的自定义搜索参数代码:

<?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();
} ?>

//展示食谱
试试这个

$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
}

经过这么多的研究,我找到了另一个。我通过一些php操作将复数术语改为单数。这是我正在分享的

$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,
);

使用哪种函数?如果配方是一个类别,只需使用类别分类法并传递蛋糕进行匹配,这将帮助您获得结果。您所做的将尝试匹配文章标题和搜索键,您认为这应该为您提供文章吗?我正在使用get_posts()function@PrafullaKumarSahurecipes是post类型,我正在对给定的参数使用get_posts()函数。@SandePathore在这里发布您的函数,并让我们知道“蛋糕”是什么?帖子名、分类法名称还是?