Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.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
Php 按不起作用的标签或类别搜索产品_Php_Wordpress_Search - Fatal编程技术网

Php 按不起作用的标签或类别搜索产品

Php 按不起作用的标签或类别搜索产品,php,wordpress,search,Php,Wordpress,Search,我正在进行搜索。我正在尝试按标签或类别搜索产品。我尝试了下面的代码,但它不起作用。我越来越 什么也没找到 此外,下面的代码仅适用于标题和内容 你能帮我解决这个问题吗 <?php /** * The template for displaying search results pages * * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result * * @pac

我正在进行搜索。我正在尝试按标签或类别搜索产品。我尝试了下面的代码,但它不起作用。我越来越

什么也没找到

此外,下面的代码仅适用于标题和内容

你能帮我解决这个问题吗

<?php
/**
 * The template for displaying search results pages
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#search-result
 *
 * @package CoolPickings
 */

get_header();
?>

    <section id="primary" class="content-area mainSearch">
        <main id="main" class="site-main">
            <div class="equalPadding">
                <div class="cp-seeWrapper">
        <?php 

                    if ( have_posts() ) : 
                    ?>
           <div class="row">
            <?php   

       while (have_posts()){the_post();?>
         <div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 col-xs-12 ">
                <div class="cp-shadow cp-seeSinglePostWrapper">
                <?php the_post_thumbnail();?>
                    <div class="bg-white single-post-box">
                    <div class="d-flex cp-CategoryList">
                     <div class="seeDate"><?php echo get_the_date('F j, Y'); ?></div>
                        <div class="cp_cat_list">
                            <?php $cat = get_the_category();
                            ?>

                            <a href="<?php echo esc_url( get_category_link( $cat[0]->term_id ) );?>"><?php echo $cat[0]->cat_name?></a><?php //the_category(''); 

                            ?>
                        </div>
                    </div>
                        <div class="cp-b-content"><h2><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( the_title_attribute( 'echo=0' ) ); ?>"><?php echo wp_trim_words(get_the_title(), 12, '...'); ?></a></h2></div>
                        <p><?php echo wp_trim_words(get_the_excerpt(), 25, '...'); ?></p>
                </div>
                </div>
                </div>
             <?php } ?>

            <?php //endwhile;

            //the_posts_navigation();

        else :

            get_template_part( 'template-parts/content', 'none' );

        endif;
        ?>
                    </div>
        </div>
        </div>
        </main><!-- #main -->
    </section><!-- #primary -->

<?php
get_sidebar();
get_footer();


请尝试下面的代码。唯一的区别是使用
术语
作为数组

$getSearch=get_search_query();
$args=数组(
“tax_query”=>数组(
'关系'=>'或',
排列(
“分类法”=>“产品标签”,
'字段'=>'段塞',
'terms'=>array($getSearch)//将术语用作数组
),
排列(
“分类法”=>“产品分类”,
'字段'=>'段塞',
'terms'=>array($getSearch)//将术语用作数组
)
),
“post_类型”=>“产品”
);
$thew_query=newwp_query($args);
// ... functions.php
添加操作('pre_get_posts'、'my_search_exclude');
函数my\u search\u exclude($query)
{
如果(!$query->is_admin&&$query->is_search&&$query->is_main_query()){
$query->set('s','');
}
}

您可以在此处找到更多信息:

请给我一些时间检查此项。请检查变量
$getSearch
它返回的内容,并确保该标记或类别存在。我在搜索字段中输入“测试”。然后我打印($getSearch)我得到了我的输出。现在“Test”是一个标签,它已经添加到我的一个产品中。好的,您没有使用名称进行搜索。你的搜索是用slug。在这种情况下,将测试tag测试段塞。否则,将
字段
的值更改为'name',如下所示
'field'=>'name'
。我尝试了标题和内容,但它们也不起作用。我投票将此问题作为主题外的问题关闭,因为这是WordPress堆栈上的问题exchange@TomJNowell,我必须回答不同的问题。在这里,我要求标签和类别。