2015-10-17 64 views
1

任何人都可以幫助我在WordPress中查詢自定義帖子嗎? 我要查詢多個條件:由多個條件查詢WordPress的自定義帖子

if(get_post_meta(get_the_ID(), 'nt_status', true) == "for-sale" && get_post_meta($post->ID, "nt_wlasnosc", true)!= "udział" && get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "85" && get_post_meta(get_the_ID(), 'nt_listprice', true)/get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "4847.40" && has_term('mieszkanie', 'propertytype') && has_term('poznan', 'location')) :?> 
     return true 
    <?php endif; ?> 

    <?php if(get_post_meta(get_the_ID(), 'nt_status', true) == "for-sale" && get_post_meta($post->ID, "nt_wlasnosc", true)!= "udział" && get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "85" && get_post_meta(get_the_ID(), 'nt_listprice', true)/get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "4126.68" && has_term('mieszkanie', 'propertytype') && has_term('powiat-poznanski', 'location')) :?> 
     return true 
    <?php endif; ?> 

    <?php if(get_post_meta(get_the_ID(), 'nt_status', true) == "for-sale" && get_post_meta($post->ID, "nt_wlasnosc", true)!= "udział" && get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "110" && get_post_meta(get_the_ID(), 'nt_listprice', true)/get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "4847.40" && has_term('dom', 'propertytype') && has_term('poznan', 'location')) :?> 
     return true 
    <?php endif; ?> 

    <?php if(get_post_meta(get_the_ID(), 'nt_status', true) == "for-sale" && get_post_meta($post->ID, "nt_wlasnosc", true)!= "udział" && get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "110" && get_post_meta(get_the_ID(), 'nt_listprice', true)/get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "4126.68" && has_term('mieszkanie', 'propertytype') && has_term('powiat-poznanski', 'location')) :?> 
     return true 
    <?php endif; ?> 

    <?php if(get_post_meta(get_the_ID(), 'nt_status', true) == "pierwotny" && get_post_meta($post->ID, "nt_wlasnosc", true)!= "udział" && get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "85" && get_post_meta(get_the_ID(), 'nt_listprice', true)/get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "5924,60" && has_term('mieszkanie', 'propertytype') && has_term('poznan', 'location')) :?> 
     return true 
    <?php endif; ?> 

    <?php if(get_post_meta(get_the_ID(), 'nt_status', true) == "pierwotny" && get_post_meta($post->ID, "nt_wlasnosc", true)!= "udział" && get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "85" && get_post_meta(get_the_ID(), 'nt_listprice', true)/get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "5043,72" && has_term('mieszkanie', 'propertytype') && has_term('powiat-poznanski', 'location')) :?> 
     return true 
    <?php endif; ?> 

    <?php if(get_post_meta(get_the_ID(), 'nt_status', true) == "pierwotny" && get_post_meta($post->ID, "nt_wlasnosc", true)!= "udział" && get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "110" && get_post_meta(get_the_ID(), 'nt_listprice', true)/get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "5924,60" && has_term('dom', 'propertytype') && has_term('poznan', 'location')) :?> 
     return true 
    <?php endif; ?> 

    <?php if(get_post_meta(get_the_ID(), 'nt_status', true) == "pierwotny" && get_post_meta($post->ID, "nt_wlasnosc", true)!= "udział" && get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "110" && get_post_meta(get_the_ID(), 'nt_listprice', true)/get_post_meta(get_the_ID(), 'nt_plot_size', true) <= "5043,72" && has_term('dom', 'propertytype') && has_term('powiat-poznanski', 'location')) :?> 
     return true 
    <?php endif; ?> 

我有模板,並知道它可以通過$args['meta_query'][] = array(with AND & OR relative)做,但也許有人有簡單的解決方案?

+1

'meta_query'是您最好的選擇在這裏,和大概只有選項,除非你想運行一個自己不應該做的自定義SQL查詢 –

回答

0

是否有任何選擇使用此條件來存儲屬性元信息?是這樣的:如果條件爲真 - >屬性元= 1

事情是這樣的:

if(get_post_meta(get_the_ID(), 'nt_status', true) == "for-sale" && get_post_meta($post->ID, "nt_wlasnosc", true)!= "udział") :?> 
get_post_meta(get_the_ID(), 'nt_mdm', true) = 1 
<?php endif; ?> 

我不知道我怎麼可以存儲這些信息來查詢?

get_post_meta(get_the_ID(), 'nt_mdm',真)= 1 < - 這不起作用

然後簡單的查詢:

$args['meta_query'][] = array(
    'key' => 'nt_mdm', 
    'value' => 1, 
    'compare' => 'IN' 
); 
相關問題