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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀