【发布时间】:2015-10-16 15:24:47
【问题描述】:
有人可以帮我解决这个问题吗,我已经花了 8 多个小时研究并试图自己解决这个问题。所以我想我会在这里开一个帐户并试试我的运气......
我正在为房地产经纪人创建一个网站以添加他们的列表。所以我为列表创建了一个自定义帖子类型。在这个自定义帖子类型中,我使用以下代码添加了自定义输入(这只是一个 sn-p,因此您可以看到我是如何定义每个自定义字段的):
$meta = get_post_meta($post->ID,'_listing_meta',TRUE);
?>
<p><label>City:</label><input name="listing_meta[city]" value="<?php echo $meta['city']; ?>" /></p>
<p><label>Area/Region:</label><input name="listing_meta[region]" value="<?php echo $meta['region']; ?>" /></p>
<p><label>Price:</label><input name="listing_meta[price]" value="<?php echo $meta['price']; ?>" /></p>
<p><label>MLS#:</label><input name="listing_meta[mls]" value="<?php echo $meta['mls']; ?>" /></p>
<?php
接下来,在我的 content.php 文件中,我会这样显示价格:
<?php
$meta = get_post_meta($post->ID,'_listing_meta',TRUE);
echo '<div class="listing-price">$'.$meta['price'].'</div>';
?>
就自定义字段而言,这非常有效。但我一辈子都无法按价格顺序对列表进行排序......
如果这些信息足以帮助我,请告诉我。如果您还需要什么,我很乐意提供。
这是我的循环(它只是标准的二十五循环):
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
// End the loop.
endwhile;
?>
【问题讨论】:
-
你能分享你的循环/你是如何查询这些帖子的吗?
-
我在我的问题中添加了我正在使用的循环:)
标签: php wordpress custom-post-type