我正在尝试获得以下信息:
州
-医疗保健(类别)
-城市
---属性1
---属性2
我正在查询以获取:
州
-医疗保健(类别)
-属性1
-属性2
我也不知道如何让City成为副标题!
这是我的代码:
<h1 style="padding-bottom: 30px; font-weight: 600;">South Carolina</h1>
<?php //start by fetching the terms for the animal_cat taxonomy
$terms = get_terms( 'property-category', array(
'orderby' => 'count',
'hide_empty' => 0
) );
// now run a query for each animal family
foreach( $terms as $term ) {
// Define the query
$args = array(
'post_type' => 'property',
'property-category' => $term->slug,
'meta_query' => array(
array (
'key' => 'state',
'value' => 'SC'
),
array(
'key' => 'available',
'compare' => '=',
'value' => '1'
)
)
);
$query = null;
$query = new WP_Query( $args );
// output the category name in a heading tag
if( $query->have_posts() ) :
echo'<div class="collapsible"> ' . $term->name . ''; echo' <span style="font-size:12px; vertical-align: middle;">(' . $query->post_count . ')</span></div>';
// output the post titles in a list
echo '<ul class="content">';
// Start the Loop
while ( $query->have_posts() ) : $query->the_post(); ?>
<li style="font-size: 12px; list-style: none; text-transform: none; line-height: 30px; padding-left: 15px;" id="post-<?php the_ID(); ?>">
<?php the_field('town'); ?>
// ****THIS IS WHERE I NEED TO SHOW PROPERTIES UNDER CITY???
<ul>
<li style="font-size: 12px; list-style: none; text-transform: none; line-height: 30px; padding-left: 15px;" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
</ul>
</li>
<?php
endwhile;
endif;
echo '</ul>';
// use reset postdata to restore orginal query
wp_reset_postdata();
} ?>
我完全陷入困境,我是否需要设置另一个查询?
编辑
我现在有了这个,它在该城市/城镇的每个可用属性列表上方显示了城市/城镇,但是它像这样复制了城市/城镇标题:
健康护理
索尔兹伯里
-医疗办公室A
夏洛特
-医务室D
索尔兹伯里
-医务室B
夏洛特
-医疗办公室C
这是我希望它显示的方式:
健康护理
索尔兹伯里
-医疗办公室A
-医务室B
夏洛特
-医务室D
-医疗办公室C
这是我的代码:
<div id="sidebar1">
<h1 style="padding-bottom: 30px; font-weight: 600; padding-left: 50px;">North Carolina</h1>
<?php //start by fetching the terms for the animal_cat taxonomy
$terms = get_terms( 'property-category', array(
'orderby' => 'count',
'hide_empty' => 0
) );
// now run a query for each animal family
foreach( $terms as $term ) {
// Define the query
$args = array(
'post_type' => 'property',
'property-category' => $term->slug,
'meta_query' => array(
array (
'key' => 'state',
'value' => 'NC'
),
array(
'key' => 'available',
'compare' => '=',
'value' => '1'
)
)
);
$query = null;
$query = new WP_Query( $args );
// output the category name in a heading tag
if( $query->have_posts() ) :
echo'<div class="collapsible G"> ' . $term->name . ''; echo' <span style="font-size:12px; vertical-align: middle;">(' . $query->post_count . ')</span></div>';
// output the post titles in a list
echo '<ul class="content">';
// Start the Loop
while ( $query->have_posts() ) : $query->the_post(); ?><?php endwhile;
echo '<ul style="margin-left: 0;">';
// Start second Loop
$args = array(
'post_type' => 'property',
'meta_query' => array (
array (
'key' => 'state',
'value' => 'NC',
),
array(
'key' => 'town',
)
)
);
while ( $query->have_posts() ) : $query->the_post(); ?>
<div><?php the_field('town'); ?></div>
<li class="city" id="post-<?php the_ID(); ?>">
<li style="font-size: 15px; list-style: none; text-transform: none; line-height: 30px;" id="post-<?php the_ID(); ?>">
<a class="prop" href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <i class="fas fa-angle-right"></i>
</li>
<?php
endwhile;
endif;
echo '</ul></li></ul>';
// use reset postdata to restore orginal query
wp_reset_postdata();
} ?>
</div>
我在做什么错了?