通过多种条件查询Wordpress自定义帖子

时间:2015-10-17 06:33:29

标签: wordpress custom-post-type

有人可以帮我查询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 个答案:

答案 0 :(得分:0)

是否有使用此条件存储到属性元信息的选项?类似于:if condition true - &gt; property meta = 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',true)= 1&lt; - 这不起作用

然后简单查询:

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