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?

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:( 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

1 Answer 1

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:)

Not the answer you're looking for? Browse other questions tagged or ask your own question.