【问题标题】:WordPress orderby a custum field, sort listing by custom fieldWordPress 按自定义字段排序,按自定义字段排序列表
【发布时间】:2017-07-30 01:04:00
【问题描述】:

我正在使用此代码显示按“postnr”排序的列表,postnr 是自定义字段。

$config = [
    "s" => $_GET["s"],
    "order" => "ASC",
    "orderby" => "postnr"
];

如何在 WordPress 中对 orderby 自定义字段“postnr”进行排序。

【问题讨论】:

    标签: php jquery mysql wordpress sorting


    【解决方案1】:

    您必须使用'orderby' => 'meta_value' 并将meta_key 定义为'meta_key' => 'postnr',

    代码如下:

    $config = [
        "s" => $_GET["s"],
        "order" => "ASC",
        'meta_key' => 'postnr',
        'orderby' => 'meta_value' //or 'meta_value_num'
    ];
    

    参考::Order & Orderby Parameters

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      相关资源
      最近更新 更多