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 |1 Answer
Reset to default 0I 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:)
'orderby' => 'title'
? – Sally CJ Commented Oct 24, 2019 at 9:59WP_Query
instead - and if you got stuck, you can come back here. – Sally CJ Commented Oct 25, 2019 at 1:00