douliaotong4944 2017-03-14 11:09
浏览 26
已采纳

过滤Word中的Wordpress数据

I have following Wordpress Code, which results in a list of properties.

    $args = array( 'posts_per_page' => 5, 'post_type'=> 'property');

    $myposts = get_posts( $args );

    foreach ( $myposts as $property_data ): 

        $meta = get_post_meta( $property_data->ID );

        $vdo_url = wp_get_attachment_url( $meta[fave_video_image][0] );
        $images =  wp_get_attachment_url( $meta[fave_property_images][0]);
        $city = wp_get_post_terms($property_data->ID, 'property_city');
        $type = wp_get_post_terms($property_data->ID, 'property_type');
        $status1 = wp_get_post_terms($property_data->ID, 'property_status');

        ?>
                <tr>
                    <td class="date">
                      <h5><input type="checkbox" class="propcheckbox" id="property" name="filedata[]" value="<?php echo $property_data->ID; ?>"> <?php echo $property_data->post_title; ?></h5>
                    </td>
                    <td class="hidden-xs hidden-sm">
                        <?php echo get_the_post_thumbnail( $property_data->ID ); ?>
                    </td>
                    <td>
                        <h5><?php echo $city[0]->name; ?></h5>
                    </td>
                    <td class="text-center">
                        <h5><?php echo $type[0]->name; ?></h5>
                    </td>
                    <td class="text-center">
                        <h5><?php echo $status1[0]->name ?></h5>
                    </td>
                    <td>
                        <h5><?php echo $property_data->post_date;  ?></h5>
                    </td>
                </tr>

    <?php endforeach; 

I want now to show only the properties where the property_status is not "verkauft". The property_status is in the wp_terms table.

What do I need to add/change?

  • 写回答

2条回答 默认 最新

  • duanhe7471 2017-03-14 11:43
    关注

    You can do it on the query level:

    $args = array( 
     'posts_per_page' => 5, 
     'post_type'=> 'property',
     'tax_query' => array(
        array(
            'taxonomy' => 'property_status',
            'field'    => 'slug',
            'terms'    => array( 'verkauft' ),
            'operator' => 'NOT IN'
        ),
      ),
    );
    
    $myposts = get_posts( $args );
    ...
    

    This should get you all the properties that do not have that status. You can test it and see if that is correct.

    Read more on the taxonomy queries here: https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集