首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自自定义MetaBox的Wp查询排序顺序

问来自自定义MetaBox的Wp查询排序顺序
EN

WordPress Development用户
提问于 2018-11-26 20:51:11
回答 1查看 1.3K关注 0票数 0

我正试图根据meta_key交易金额对帖子列表进行排序,这将首先显示最高的交易金额,并将其降低到较小的交易金额。这笔交易金额将在1000到900万之间。目前,下面的代码正在根据第一个数字对交易金额进行排序。因此,如果我有一个事务,即6,000和6,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,他们把他们放在一起,而不是先显示600万。交易金额从CMB2中的自定义CMB2中提取。在我的代码中有什么东西是我遗漏的,那就是排序没有识别逗号后面的数量吗?

我的WP_Query

代码语言:javascript
复制
      'transactions', 
                'paged'             => $paged, 
                'posts_per_page'    => 50,
                'orderby'           => array( 'meta_value_num' => 'ASC' ),
                'meta_key'          => 'deal_amount',
            ) );

        if ( $transaction->have_posts() ) : ?>
        have_posts() ) : $transaction->the_post();
            $deal_amount = get_post_meta( get_the_ID(), 'deal_amount', true );
            $property_type = get_post_meta( get_the_ID(), 'property_type', true );
            $property_size = get_post_meta( get_the_ID(), 'property_size', true );
        ?>
        

            
                ', ''); ?>
                The MetaBoxadd_action( 'cmb2_admin_init', 'transactions_metabox' );
 function transactions_metabox() {
$prefix = 'transactions_';
$cmb = new_cmb2_box( array(
    'id'            => $prefix . 'transactions',
    'title'         => esc_html__( 'Transactions', 'cvcapital' ),
    'object_types'  => array( 'transactions', ),

) );
$cmb->add_field( array(
    'name'              => 'Deal Amount',
    'id'                => 'deal_amount',
    'type'              => 'text',
    'before_field'      => ' . esc_html($deal_amount) . ''; ?>
                

                

                ID, 'loan-type', '', ', ', '' ) ; echo strip_tags($terms_as_text); ?>

The MetaBox

A1, 'column' => true, // Display field value in the admin post-listing columns 'before_display' => ' . esc_html($deal_amount) . ''; ?>

ID, 'loan-type', '', ', ', '' ) ; echo strip_tags($terms_as_text); ?>

The MetaBox

A1, ) ); . esc_html($deal_amount) . ''; ?>

ID, 'loan-type', '', ', ', '' ) ; echo strip_tags($terms_as_text); ?>

The MetaBox

A1

EN

回答 1

WordPress Development用户

发布于 2018-11-27 15:02:14

下面是在“jacobPeattie”的指导下的工作示例。有一次我去掉了逗号,一切都很好。我在交易金额中添加了number_format,以自动添加前面的逗号。

代码语言:javascript
复制
 'transactions', 
            'paged'             => $paged, 
            'posts_per_page'    => 50,
            'orderby'           => array( 'meta_value_num' => 'ASC' ),
            'meta_key'          => 'deal_amount',
        ) );

    if ( $transaction->have_posts() ) : ?>
    have_posts() ) : $transaction->the_post();
        $deal_amount = get_post_meta( get_the_ID(), 'deal_amount', true );
        $property_type = get_post_meta( get_the_ID(), 'property_type', true );
        $property_size = get_post_meta( get_the_ID(), 'property_size', true );
    ?>
    

        
            ', ''); ?>
             . number_format($deal_amount) . ''; ?>
            

            

            ID, 'loan-type', '', ', ', '' ) ; echo strip_tags($terms_as_text); ?>
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/320277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档