首页 > 解决方案 > Wordpress如何按订单输入值排序

问题描述

当您在 Wordpress 中创建帖子时,有一个名为“订单”的字段。

我怎样才能使它工作,例如,我把5帖子5th放在页面上显示的位置?

我试过这个但没有奏效:

<?php
            $args = array(
               'post_type' => 'team',
               'posts_per_page' => 30,
               'orderby' => 'meta_value_num',
               'order' => 'ASC'
            );
            $the_query = new WP_Query($args);
            if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post();
            ?>

标签: phpwordpresswordpress-themingcustom-wordpress-pageswordpress-admin

解决方案


如果“订单”是一个自定义字段,那么您可以执行以下操作:

$the_query = new WP_Query(array(
    'post_type' => 'team',
    'posts_per_page' => 30,
    'meta_key' => 'order',
    'orderby' => 'meta_value',
    'order' => 'ASC',
  ));

请让我知道这对你有没有用!


推荐阅读