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_Dropdown - Fatal编程技术网

Wordpress 按特定类别排序

Wordpress 按特定类别排序,wordpress,search,dropdown,Wordpress,Search,Dropdown,我在自定义搜索中使用此代码,但它选择了我网站上的所有产品,我希望它仅链接到页面的自定义搜索 我必须添加什么来确保只有我网站上的轮胎被排序,因为当我用这个轮胎进行搜索时,它只选择轮胎,但当我对它们进行排序时,它会显示网站上的所有产品 先谢谢你 守则: <div id="sortby"> SORT BY: &nbsp; <select class="dropdown-class" name="sort-posts&q

我在自定义搜索中使用此代码,但它选择了我网站上的所有产品,我希望它仅链接到页面的自定义搜索

我必须添加什么来确保只有我网站上的轮胎被排序,因为当我用这个轮胎进行搜索时,它只选择轮胎,但当我对它们进行排序时,它会显示网站上的所有产品

先谢谢你

守则:

<div id="sortby"> SORT BY: &nbsp;
    <select class="dropdown-class" name="sort-posts" id="sortbox" onchange="document.location.search=this.options[this.selectedIndex].value;">
    <option disabled>Sort by</option>
    <option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'date' && isset($_GET["order"]) && trim($_GET["order"]) == 'DESC' ){ echo 'selected'; } ?> value="?orderby=date&order=DESC">Newest</option>
    <option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'date' && isset($_GET["order"]) && trim($_GET["order"]) == 'ASC' ){ echo 'selected'; } ?>  value="?orderby=date&order=ASC">Oldest</option>
    <option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'title' && isset($_GET["order"]) && trim($_GET["order"]) == 'ASC' ){ echo 'selected'; } ?> value="?orderby=date&order=DESC" value="?orderby=title&order=ASC">A-Z Asc</option>
    <option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'title' && isset($_GET["order"]) && trim($_GET["order"]) == 'DESC' ){ echo 'selected'; } ?>  value="?orderby=title&order=DESC">A-Z Desc</option>
    <option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'views' && isset($_GET["order"]) && trim($_GET["order"]) == 'ASC' ){ echo 'selected'; } ?> value="?orderby=views&order=ASC">Views Asc</option>
    <option <?php if( isset($_GET["orderby"]) && trim($_GET["orderby"]) == 'views' && isset($_GET["order"]) && trim($_GET["order"]) == 'DESC' ){ echo 'selected'; } ?> value="?orderby=views&order=DESC">Views Desc</option>
   </select>
    </div>
排序依据:
排序
value=“?orderby=date&order=ASC”>最早
value=“?orderby=title&order=DESC”>A-Z DESC
value=“?orderby=views&order=DESC”>视图描述
和自定义搜索:

<?php 



$optionLargura = isset($_GET['largura']) ? $_GET['largura'] : false;
$optionAltura = isset($_GET['altura']) ? $_GET['altura'] : false;
$optionDiametro = isset($_GET['diametro']) ? $_GET['diametro'] : false;
$optionTipoPneu = isset($_GET['tipoPneu']) ? $_GET['tipoPneu'] : false; 
$marqueDePneu = isset($_GET['DePneu']) ? $_GET['DePneu'] : false; 
$catDePneus = isset($_GET['DePneus']) ? $_GET['DePneus'] : false; 

$coin="CHF";


        $tax_query = array('relation' => 'AND');
        if ($optionLargura!='')
        {
            $tax_query[] =  array(
                'taxonomy'        => 'pa_largeur',
                'field'           => 'slug',
                'terms'           =>  array($optionLargura),
                'operator'        => 'IN',
            );
        }
        if ($optionAltura!='')
        {
            $tax_query[] =  array(
                'taxonomy'        => 'pa_hauteur',
                'field'           => 'slug',
                'terms'           =>  array($optionAltura),
                'operator'        => 'IN',
            );
        }
        if ($optionDiametro!='')
        {
            $tax_query[] =  array(
                'taxonomy'        => 'pa_diametre',
                'field'           => 'slug',
                'terms'           =>  array($optionDiametro),
                'operator'        => 'IN',
            );
        }
        if ($optionTipoPneu!='')
        {
            $tax_query[] =  array(
                'taxonomy'        => 'pa_type-de-pneu',
                'field'           => 'slug',
                'terms'           =>  array($optionTipoPneu),
                'operator'        => 'IN',
            );
        }

          if ($marqueDePneu!='')
        {
            $tax_query[] =  array(
                'taxonomy'        => 'pa_marque-pneus',
                'field'           => 'slug',
                'terms'           =>  array($marqueDePneu),
                'operator'        => 'IN',
            );
        }

                      if ($catDePneus!='')
        {
            $tax_query[] =  array(
                'taxonomy'        => 'pa_categories-de-pneus',
                'field'           => 'slug',
                'terms'           =>  array($catDePneus),
                'operator'        => 'IN',
                
            );
        }


$args  = array( 
             'post_type'           => array('product', 'product_variation'),
            'post_status'         => 'publish',
            'posts_per_page' => get_option('posts_per_page'),
            'paged'          => $paged,
            'tax_query'      => $tax_query,
            'orderby' => 'price',
             'order' => 'asc',
                        
              );


$prods=new WP_Query($args);

    if( $prods->have_posts() ){

            $content = '<form class="cart" action="https://ahcor-autoshop.ch/panier" method="post" enctype="multipart/form-data" wtx-context="D6ECEB0A-195E-4229-9B5D-1A13E3D7E5AF">';
            

        
        

        while($prods->have_posts()) : 
            $product=$prods->the_post();
            $content .= '<div class="search-col" id="search-product-'.get_the_ID().'">';

                        $attachment_url='<div class="w10 floatleft"><img alt="' . get_the_title() . '" src="https://ahcor-autoshop.ch/wp-content/uploads/2019/11/pneu-de-inverno.png" width="80"></div>';
                        $attachment_id=get_post_thumbnail_id(get_the_ID());
                        if($attachment_id){
                            $post_attachment_url=wp_get_attachment_url($attachment_id);
                            if($post_attachment_url)$attachment_url='<div class="w15 floatleft"><img alt="' . get_the_title() . '" src="'.$post_attachment_url.'" width="80"></div>';
                        }
                        $content.=$attachment_url;
        
                        //$content .= '<div class="w60 floatleft"><a href="https://ahcor-autoshop.ch/produit/'.$row->post_name.'/">' . $row->post_title . '</a>';
                        $content .= '<div class="w60 floatleft"><a href="'.get_the_permalink().'">' . get_the_title() . '</a>';
                        $content .= '<div class="fullwidth floatleft"><small class="inline floatleft">Tags</small></div>';

                        $price=get_post_meta(get_the_ID(),'_regular_price',true);
                        if(date("Y-m-d") != "2020-12-30")
                        {
        
                            $calcAscTotal= $price ;

                            $content .= '<h3 style="color:#d52b1e;"><del style="opacity: .5; display: inline-block; margin: 15px;color: #545454;"></del> CHF '.round($calcAscTotal, 0, PHP_ROUND_HALF_UP).' .- '.'</h3>'; 
                        }
                        else
                        {
                            $content .= '<h3><small>Seulement</small> '. $price.' CHF.- '.'</h3>'; 
                        }
                        $content .= '</div>'; 
                        $content .= '<button type="submit" name="add-to-cart" value='. get_the_ID() .' class="single_add_to_cart_button button alt w20 floatright">Panier</button>'; 
                        //$content .= '</div>';
            $content.='</div>';
       endwhile;
       $content.= '<a onclick="window.history.go(-1); return false;" href="#" class="text-red center-el bold" style="font-size:2em; padding: 20px 0">Retour</a>';
       $content.='</form>';

    }
    else{
        $content.="<h2 class='text-center'>".__('Aucun résultat trouvé','ahcor-autoshop').".</h2>";
        $content.= '<a onclick="window.history.go(-1); return false;" href="#" class="text-red center-el bold" style="font-size:2em; padding: 20px 0">Retour</a>';
    }      
      if($content != "" )echo $content;
 if ($prods->max_num_pages > 1) : // custom pagination  
   
    $orig_query = $wp_query; // fix for pagination to work
    $wp_query = $prods;
    ?>
    <nav class="prev-next-posts">
        <div class="prev-posts-link" class="text-red center-el bold" style="font-size:2em; text-align: right;">
            <?php echo get_next_posts_link( 'Suivant', $prods->max_num_pages ); ?>
        </div>
        <div class="next-posts-link" class="text-red center-el bold" style="font-size:2em; padding: 20px 0" >
            <?php echo get_previous_posts_link( 'Précédent' ); ?>
        </div>
    </nav>
    <?php
    $wp_query = $orig_query; // fix for pagination to work
    ?>
<?php endif; ?>

有人有主意吗?