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?

  • 'orderby' => 'title' ? – Sally CJ Oct 24 at 9:59
  • @SallyCJ, thanks for your response, I allready tried that but that did not work eihter:( – user2812779 Oct 24 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 Oct 25 at 1:00
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:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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