我有一个旧项目(自定义帖子类型查询),需要修改,我的记忆/技能水平不足,无法做什么。使用下面的代码,I\'m needing to return the first query in alphabetical order, by title. 使用orderby => title
和order => asc
(第9行和第10行)无效。不过,它在第二个查询(第39行和第40行)中起作用。我最初让一位同事帮我设置,但他无法帮助我进行调整。SE社区的任何帮助都将不胜感激。
<?php get_header(); ?>
<h1>Properties in <?php the_terms(\'\', \'region\');?></h1>
<?php
$queried_object = get_queried_object();
$term_id = $queried_object->term_id;
$args = array(
\'post_type\' => \'rental\',
\'posts_per_page\' => -1,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'region\',
\'field\' => \'slug\',
\'terms\' => ".$queried_object->slug."
)
)
);
$query = get_posts( $args );
$property=array();
if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $term_list = wp_get_post_terms($post->ID, \'property\', array("fields" => "ids"));
foreach($term_list as $id)
{
array_push($property,$id);
}
?>
<?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
<?php wp_reset_query();
$property=array_unique($property);
foreach($property as $ids)
{$terms=get_term_by(\'id\', $ids, \'property\');
?><h1><?php echo $terms->name ?></h1><?php
?>
<?php
$args1 = array(
\'post_type\' => \'rental\',
\'posts_per_page\' => -1,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'property\',
\'field\' => \'id\',
\'terms\' => $ids
),
array(\'taxonomy\' => \'region\',
\'field\' => \'slug\',
\'terms\' => ".$queried_object->slug.")
)
);
$query1 = new WP_Query( $args1 );
foreach($query1->posts as $posts)
{
$region_array=get_the_terms($posts->ID,\'region\');
$property_array = get_the_terms( $posts->ID, \'property\' );
$bedrooms_array = get_the_terms( $posts->ID, \'bedrooms\' );
$bathrooms = get_the_terms( $posts->ID, \'bathrooms\' );
$views = get_the_terms( $posts->ID, \'view\' );
$rows = get_field(\'rental_images\',$posts->ID); // get all the rows
$first_row = $rows[0]; // get the first row
$first_row_image = $first_row[\'rental_images-image\' ]; // get the sub field value
$image = wp_get_attachment_image_src( $first_row_image, \'thumbnail\' );
?>
<div class="rental">
<div class="pic">
<a href="<?php echo get_permalink($posts->ID);?>"><img src="<?php echo $image[0]; ?>" /></a>
</div><!-- .pic -->
<div class="text">
<ul>
<li><?php echo $posts->post_title ?></li>
<?php
if($bedrooms_array!=\'\' )
{$i=0;
?><li>Bedrooms:<?php
foreach($bedrooms_array as $bed)
{
if($i==0)
{
$i=1;
?>
<?php echo $bed->name; ?>
<?php }
else
{
echo ", ".$bed->name;
}
}
?></li><?php
}
else
{
}?>
<?php
if($bathrooms!=\'\')
{?><li>Bathrooms: <?php
$i=0;
foreach($bathrooms as $bath)
{
if($i==0)
{
echo $bath->name;
$i=1;
}
else
{
echo ", ".$bath->name;
}}?></li><?php
}?>
<?php
if($views!=\'\')
{?><li>View: <?php
$i=0;
foreach($views as $v)
{
if($i==0)
{
$i=1;
echo $v->name;
}
else
{
echo ", ".$v->name;
}
}?></li><?php }?>
</ul>
</div><!-- .text -->
</div><!-- .rental -->
<?php }
}?>
<?php get_footer(); ?>