1

我试图通过自定义字段中设置的数值简单地对帖子进行排序。我已经搜索了在线资源,但仍然无法确定为什么这不起作用。有任何想法吗?

<?php 
    $args = array(
        'post_type' => 'calendar',
        'meta_key' => 'event_date_new',
        'orderby' => 'meta_value_num',
        'order' => 'DESC'
    );
    $loop = new WP_Query($args);
    while ( $loop->have_posts() ) : $loop->the_post(); ?>
        <h3><?php the_title(); ?></h3>
        <?php echo the_field('event_date_new'); ?>
    <?php endwhile; ?>
4

2 回答 2

1

此查询有效

$wp_query_args['post_type'] = 'event';
$wp_query_args['paged']     = $paged;
$wp_query_args['posts_per_page'] = 10;
$wp_query_args['orderby']   = 'meta_value_num';
$wp_query_args['order']     = 'DESC';
$wp_query_args['meta_key']  = 'event_end_date';
$wp_query_args['meta_query']= array(
                                array(
                                    'key' => 'event_end_date',
                                    'compare' => '<',
                                    'value' => date('Ymd'),
                                )
                            );

此查询不起作用。

$wp_query_args['post_type'] = 'event';
$wp_query_args['paged']     = $paged;
$wp_query_args['posts_per_page'] = 10;
$wp_query_args['orderby']   = 'meta_value_num';
$wp_query_args['order']     = 'ASC';
$wp_query_args['meta_key']  = 'event_start_date';
$wp_query_args['meta_query']= array(
                                'relation' => 'OR',
                                array(
                                    'key' => 'event_start_date',
                                    'compare' => '>=',
                                    'value' => date('Ymd'),
                                ),
                            array(
                                'key' => 'event_end_date',
                                'compare' => '>=',
                                'value' => date('Ymd'),
                            )
                        );
于 2013-07-29T12:54:57.800 回答
1

你试过 'orderby' => 'meta_value_num meta_value'or'orderby' => 'meta_value meta_value_num'吗?

于 2012-11-21T02:50:18.677 回答