首页 > 解决方案 > update_post_meta 属性可见性?

问题描述

我正在尝试查找如何显示导入的属性列表。问题是元数据,导入后属性在前端不可见,我需要手动更新每个项目。如何更新元数据编辑以下代码:

<?php
    $args = array(
    'posts_per_page'      => $custom_property_items_amount,
    'post_type'           => 'property',
    'orderby'   => array(
        'menu_order'=>'ASC',
        'date' =>'DESC',
    ),
    'offset'              => ( max( 1, get_query_var( 'paged' ) ) - 1 ) * $custom_property_items_amount,
    'ignore_sticky_posts' => 1,
    'post_status'         => array('publish','pending','draft','future','private'),

);
$data       = new WP_Query( $args );
?>
        <div class="<?php echo join( ' ', $wrapper_classes ) ?>">
            <?php if ( $data->have_posts() ) :
                while ( $data->have_posts() ): $data->the_post(); ?>

                    <?php ere_get_template( 'content-property.php', array(
                        'custom_property_image_size' => $custom_property_image_size,
                        'property_item_class' => $property_item_class
                    )); ?>

                <?php endwhile; 
            else: ?>
                <div class="item-not-found"><?php esc_html_e( 'Not found', 'essential-real-estate' ); ?></div>
            <?php endif; ?>
            <div class="clearfix"></div>
            <?php
            $max_num_pages = $data->max_num_pages;
            ere_get_template( 'global/pagination.php', array( 'max_num_pages' => $max_num_pages ) );
            wp_reset_postdata(); ?>
        </div>

标签: importmetadata

解决方案


解决了!问题出在这部分代码中:

if (!empty($features)) {
    foreach($features as $feature){
        $tax_query[] = array(
            'taxonomy' => 'property-feature',
            'field' => 'slug',
            'terms' => $feature
        );
        $parameters.=sprintf( __('Feature: <strong>%s</strong>; ', 'essential-real-estate'), $feature);
    }
}

$args['meta_query'] = array(
    'relation' => 'AND',
    $meta_query
);

$tax_count = count($tax_query);
if ($tax_count > 0) {
    $args['tax_query'] = array(
        'relation' => 'AND',
        $tax_query
    );
}

通过删除它,所有项目都显示出来了。


推荐阅读