Php Wordpress如何根据自定义字段对帖子进行排序

Php Wordpress如何根据自定义字段对帖子进行排序,php,html,css,wordpress,Php,Html,Css,Wordpress,我尝试了这个网站或其他网站上给出的所有解决方案,但并没有发现根据自定义字段支付包对帖子进行排序的成功。我试过下面的代码 $args = array( 'meta_key'=>'et_payment_package','meta_key'=>693 ); // Variable to call WP_Query. $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : // Sta

我尝试了这个网站或其他网站上给出的所有解决方案,但并没有发现根据自定义字段支付包对帖子进行排序的成功。我试过下面的代码

$args = array( 'meta_key'=>'et_payment_package','meta_key'=>693 );

// Variable to call WP_Query.

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) :

    // Start the Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
        the_title();
        the_excerpt();
    // End the Loop
    endwhile;
else:

// If no posts match this query, output this text.
    _e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;

wp_reset_postdata();
它表明

抱歉,没有符合您标准的帖子


您的查询参数是错误的。您有两次
meta_键。试一试

$args = array( 'meta_key'=>'et_payment_package', 'meta_value'=>693 );
并尝试指定帖子类型

例如:

$args = array(
    'post_type'  => 'my_custom_post_type',
    'meta_key'   => 'et_payment_package',
    'orderby'    => 'meta_value_num',
    'order'      => 'DESC',
    'meta_query' => array(
        array(
            'key'     => 'et_payment_package',
            'value'   => '693',
            'compare' => 'IN',
        ),
    ),
);

$query = new WP_Query( $args );

我没有所有的细节(帖子类型等),但这是你应该如何去做的。希望有帮助。

很抱歉,错误地键入了meta_键而不是meta_值。感谢您的回答。感谢您的回复,但它不起作用。它不会显示错误消息,但帖子顺序没有更改。实际上,我想根据所选的包免费显示帖子,你能在你的帖子中添加更多信息吗?这是什么自定义帖子类型,是插件还是主题?Woocommerce还是?我使用的是分类引擎主题。