最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Custom post type order by post_title

programmeradmin0浏览0评论

I got a custom post type called "employees" and this is the query I use with FacetWP (plugin we are using). We want to sort the employees by post_title.

<?php
return [
  "post_type" => [
    "employees"
  ],
  "post_status" => [
    "publish"
  ],
  "orderby" => [
    "post_title"
  ],
  "order" => [
    "ASC"
  ],
  "posts_per_page" => "99"
];

This aint working and I tried it like this:

 <?php
    return array(
    "post_type" => "employees",
    "post_status" => "publish",
    "meta_key" => "post_title",
    "orderby" => "meta_value",
    "order" => "ASC",
    "posts_per_page" => 99
  );

This gives u back nothing because the "post_title" doesnt exist in the postmeta table.

Maybe there is a very simple solution for this but I am a but lost here. How can I sort the custom post types by the post_title?

I got a custom post type called "employees" and this is the query I use with FacetWP (plugin we are using). We want to sort the employees by post_title.

<?php
return [
  "post_type" => [
    "employees"
  ],
  "post_status" => [
    "publish"
  ],
  "orderby" => [
    "post_title"
  ],
  "order" => [
    "ASC"
  ],
  "posts_per_page" => "99"
];

This aint working and I tried it like this:

 <?php
    return array(
    "post_type" => "employees",
    "post_status" => "publish",
    "meta_key" => "post_title",
    "orderby" => "meta_value",
    "order" => "ASC",
    "posts_per_page" => 99
  );

This gives u back nothing because the "post_title" doesnt exist in the postmeta table.

Maybe there is a very simple solution for this but I am a but lost here. How can I sort the custom post types by the post_title?

Share Improve this question asked Oct 24, 2019 at 9:36 user2812779user2812779 1472 silver badges9 bronze badges 3
  • 'orderby' => 'title' ? – Sally CJ Commented Oct 24, 2019 at 9:59
  • @SallyCJ, thanks for your response, I allready tried that but that did not work eihter:( – user2812779 Commented Oct 24, 2019 at 11:08
  • Well, I'd love to help you, but I don't use the plugin. Try asking/searching on their forums/site. But basically, if they can't help you, you can simply try using WP_Query instead - and if you got stuck, you can come back here. – Sally CJ Commented Oct 25, 2019 at 1:00
Add a comment  | 

1 Answer 1

Reset to default 0

I found the solution. When I take my first query and make it like this:

<?php
return [
  "post_type" => [
    "employees"
  ],
  "post_status" => [
    "publish"
  ],
  "orderby" => [
   "post_title" => "ASC"
],
  "posts_per_page" => "99"
];

the sorting is working. So I replaced:

"orderby" => [
"post_title"
],
"order" => [
"ASC"
],

with only:

"orderby" => [
"post_title" => "ASC"
],

This did the trick:)

发布评论

评论列表(0)

  1. 暂无评论