我希望有人可以幫助我。我是PHP新手,所以在工作上非常瞭解。Wordpress訂單自定義帖子類型
我正在自定義一個現有的WordPress主題,但我面臨主題高級搜索/結果的問題。
主題無法訂購搜索結果,我知道Wordpress的默認訂單是按日期排列的。目前,如果我執行搜索,結果將按日期順序顯示,但我需要結果是價格從高到低。
當前的代碼如下
<?php /* If there are no posts to display, such as an empty archive page */ ?>
<?php if (! have_posts()) : ?>
<article id="post-0" class="post error404 not-found">
<h1 class="posttitle"><?php _e('Not Found', THE_LANG); ?></h1>
<div class="entry">
<p><?php _e('Apologies, but no results were found for the requested property archive. Perhaps searching will help find a related post.', THE_LANG); ?></p>
</div>
</article>
<?php endif; ?>
<div class="nvr-prop-container row">
<?php if(have_posts()){ ?>
<div class="search-title twelve columns">
<h4><?php _e('Search Result', THE_LANG); ?> (<?php echo $wp_query->post_count; ?>)</h4>
</div>
<?php
$nvr_idnum = 0;
$nvr_typecol = "nvr-prop-col";
$nvr_imgsize = "property-image";
?>
<ul id="nvr-prop-search" class="<?php echo esc_attr($nvr_typecol); ?>">
<?php
while (have_posts()) : the_post();
$nvr_idnum++;
echo nvr_prop_get_box($nvr_imgsize, get_the_ID(), 'element columns', $nvr_unit, $nvr_cursymbol, $nvr_curplace);
$nvr_classpf="";
endwhile; // End the loop. Whew.
?>
然後我決定嘗試對結果進行排序,所以我創建
$sort_properties = new WP_Query(array(
'post_type' => 'properties',
'meta_key' => $nvr_initial.'_price',
'meta_value' => $nvr_price,
'orderby' => 'meta_value_num date',
'order' => 'DESC',
));
<?php /* If there are no posts to display, such as an empty archive page */ ?>
<?php if (! have_posts()) : ?>
<article id="post-0" class="post error404 not-found">
<h1 class="posttitle"><?php _e('Not Found', THE_LANG); ?></h1>
<div class="entry">
<p><?php _e('Apologies, but no results were found for the requested property archive. Perhaps searching will help find a related post.', THE_LANG); ?></p>
</div>
</article>
<?php endif; ?>
<div class="nvr-prop-container row">
<?php if($sort_properties->have_posts()){ ?>
<div class="search-title twelve columns">
<h4><?php _e('Search Result', THE_LANG); ?> (<?php echo $wp_query->post_count; ?>)</h4>
</div>
<?php
$nvr_idnum = 0;
$nvr_typecol = "nvr-prop-col";
$nvr_imgsize = "property-image";
?>
<ul id="nvr-prop-search" class="<?php echo esc_attr($nvr_typecol); ?>">
<?php
while ($sort_properties->have_posts()) : $sort_properties->the_post();
$nvr_idnum++;
echo nvr_prop_get_box($nvr_imgsize, get_the_ID(), 'element columns', $nvr_unit, $nvr_cursymbol, $nvr_curplace);
$nvr_classpf="";
endwhile; // End the loop. Whew.
?>
現在,當我執行搜索,職位進行排序基於價格這是太棒了,但...現在無論我如何搜索所有網站帖子現在正在顯示。
我覺得我是如此接近尋找解決方案,但我會非常感激,如果有人感冒用這個建議我。
親切的問候
小號
感謝這一點,但它並沒有做任何的結果。 – user4572969
編輯我的答案並添加了meta_query => array()部分。 – noreabu
你好,謝謝,但我擔心它不會影響結果。 <?php echo $ wp_query-> post_count; ?>顯示正確的帖子數量,但顯示的實際帖子保持不變。 – user4572969