我无法按“标题”对家庭进行排序-不确定我做错了什么。
我需要添加一些我不知道的自定义查询吗?
<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">
答案 0 :(得分:0)
如果要按帖子标题排序,则需要将orderby
参数添加到$args
中。
'orderby' => 'post_title'
请参见https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters