亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將內容蛋搜索表單與 WordPress 和 Woocommerce 相結合

將內容蛋搜索表單與 WordPress 和 Woocommerce 相結合

PHP
小怪獸愛吃肉 2022-10-28 15:36:14
我如何結合 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 使用差異。模板也是如此。目前我正在使用
查看完整描述

1 回答

?
紫衣仙女

TA貢獻1839條經驗 獲得超15個贊

如果有人在這里有同樣的問題,那么我所做的就是結合搜索結果并從差異中獲取。查詢類型


首先創建一個 Search-Result.php 文件,您的搜索表單將重定向到該文件。如您所見,我將搜索查詢存儲到變量并根據它獲取輸出。


<?php

                        $s=get_search_query();

                        $args = array(

                        's' =>$s,

                        'posts_per_page' => 10,

                        'post_type' => 'product'

                        );

                        $the_query = new WP_Query( $args );

                        if ( $the_query->have_posts() ) {

                            while ( $the_query->have_posts() ) {

                            $the_query->the_post();

                     ?>           

                  <?php wc_get_template_part( 'content', 'product' ); ?>

輸出類型 2


<?php

                $news=get_search_query();

                $argsn = array(

                's' =>$news,

                'posts_per_page' => 10,

                'post_type' => 'post'

                );


                $the_query = new WP_Query( $argsn );

                    if ( $the_query->have_posts() ) {

                        while ( $the_query->have_posts() ) {

                        $the_query->the_post();


the_title();


}?>

輸出類型 3


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

這是適合我的簡單解決方案,目前我面臨很多天的問題。


查看完整回答
反對 回復 2022-10-28
  • 1 回答
  • 0 關注
  • 145 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號