wordpress命令由两个元键查询

时间:2016-11-29 15:39:00

标签: php wordpress

我想通过两个元键来订购帖子" post_up_lvl" (显性)和" post_up_exp"。

对于前。输出必须是44321111.如果post_up_lvl repeat必须按post_up_exp排序,其中存储日期。我试过了,但它只安排了" post_up_lvl"。

CURRENT_DIR=$(pwd) && \
cd /home/fadc80/my-first-angular-cli-project && \
ng build -o $CURRENT_DIR/build && \
cd $CURRENT_DIR

2 个答案:

答案 0 :(得分:2)

参数dates不存在,您必须使用date_query,而我从未听说过WP_Query中的level参数,

这是meta_query和date_query的想法,数组必须保留,你可以借助上面的链接添加/删除/修改参数,

    'meta_query' => array(
         'relation' => 'AND'
            array(
                'key' => 'post_up_lvl',
                'value' => $today,
                'type' => 'DATETIME'
            )
            array(
                'key' => 'post_up_exp',
                'value' => $today,
                'type' => 'DATETIME'
            )
    ),
    'date_query' => array(
        array(
            'key' => 'post_up_exp',
            'value' => $today,
            'compare' => '>=',
            'type' => 'datetime'
        )
    )

答案 1 :(得分:0)

$qargs1 = array(

                'post_type'         => 'post',
                'posts_per_page'    => -1,
                'paged'             => $paged,
                'meta_query'      => array(
                    'relation'    => 'AND',
                    'level' => array(
                        'key'     => 'post_up_lvl',
                        'type'    => 'NUMERIC',
                        'compare' => 'EXISTS',
                    ),
                    'expire'    => array(
                        'key' => 'post_up_exp', // Check the start date field
                        'value' => $today, // Set today's date (note the similar format)
                        'compare' => '>=', // Return the ones greater than today's date
                        'type' => 'datetime,' // Let WordPress know we're working with numbers
                    ),
                ),
                'orderby' => array(
                    'level' => 'DESC',
                    'expire'    => 'DESC',
                        )
                );

修复了我的查询,现在可行了