将内容蛋搜索表单与 WordPress 和 Woocommerce 相结合

我如何结合 Content Egg Search 表单或使其从 WordPress 帖子和 Woocommerce 产品中进行搜索。

我想要的是

内容 Egg + WordPress + Woocommerce 搜索表单相结合

内容蛋搜索表 这里是内容蛋搜索表

<form role="search" method="get" class="search-form" action="<?php echo esc_attr(\ContentEgg\application\ProductSearchWidget::getSearchFormUri()); ?>">


      <input type="text" name="s" placeholder="Product search...">

      <input type="hidden" name="post_type" value="product" />


      <button type="submit">Search</button>


</form>

Woocommerce 搜索表单


<form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/'  ) ); ?>">

    <label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'woocommerce' ); ?></label>

    <input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Products&hellip;', 'placeholder', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'woocommerce' ); ?>" />

    <input type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" />

    <input type="hidden" name="post_type" value="product" />

</form>

WordPress 搜索表格


<form action="/" method="get">

    <label for="search">Search in <?php echo home_url( '/' ); ?></label>

    <input type="text" name="s" id="search" value="<?php the_search_query(); ?>" />

    <input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" />

</form>

所有这三个搜索表单结果都显示在 diff 上。搜索结果页面


内容蛋显示在


ce-产品-search.php


我正在使用类似的代码 - 它很有效


<?php echo do_shortcode('[content-egg module=Amazon template=grid]'); ?>

WooCommerce 和 WordPress 使用差异。模板也是如此。


目前我正在使用


小怪兽爱吃肉
浏览 74回答 1
1回答

紫衣仙女

如果有人在这里有同样的问题,那么我所做的就是结合搜索结果并从差异中获取。查询类型首先创建一个 Search-Result.php 文件,您的搜索表单将重定向到该文件。如您所见,我将搜索查询存储到变量并根据它获取输出。<?php&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $s=get_search_query();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $args = array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 's' =>$s,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'posts_per_page' => 10,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'post_type' => 'product'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $the_query = new WP_Query( $args );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( $the_query->have_posts() ) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ( $the_query->have_posts() ) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $the_query->the_post();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;?>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <?php wc_get_template_part( 'content', 'product' ); ?>输出类型 2<?php&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $news=get_search_query();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $argsn = array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 's' =>$news,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'posts_per_page' => 10,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'post_type' => 'post'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $the_query = new WP_Query( $argsn );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( $the_query->have_posts() ) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ( $the_query->have_posts() ) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $the_query->the_post();the_title();}?>输出类型 3<?php echo do_shortcode('[content-egg module=Amazon template=grid]'); ?>这是适合我的简单解决方案,目前我面临很多天的问题。
打开App,查看更多内容
随时随地看视频慕课网APP