简体   繁体   English

按标题对商店页面上的WooCommerce产品排序

[英]Sort WooCommerce Products on shop page by Title

I'm not able to sort the families by "Title" - Not sure what I'm doing wrong. 我无法按“标题”对家庭进行排序-不确定我做错了什么。

Is there something I need to add to the Custom Query that I'm not aware of? 是否需要添加一些我不知道的自定义查询?

        <h1 class="heading-14 _15mar center">Sponsored Families</h1>
       <?php 
     $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

            $args = array(
                'post_type' => 'product' ,
                'posts_per_page'=> 10 ,
                'meta_query' => array( 
                    array( 
                    'key' => '_stock_status',
                    'orderby' = 'title',
                    'value' => 'instock',
                    'compare' => '!=' ) ), 'paged' => $paged );


            $loop = new WP_Query( $args );

        if ( $loop->have_posts() ) {  
            while ( $loop->have_posts() ) : $loop->the_post();
            $image = wp_get_attachment_image_src( get_post_thumbnail_id( $loop->post->ID ), 'single-post-thumbnail' );
                global $product; ?>
                <!--img src="" width="100%;"-->
                  <div class="div-block-60 fm-block">
                   <div class="div-block-61">
                    <div class="div-block-62">
                      <div class="family-image familypic family1" style="background-image: url(<?php echo $image[0]; ?>)">
                        <!--img src="" width="100%;"-->
                      </div>
                      <div class="buckettext">

If you'd like to sort by the Post Title, you need to add the orderby parameter to your $args . 如果要按帖子标题排序,则需要将orderby参数添加到$args

'orderby' => 'post_title'

See https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters 参见https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM