我得到了一个名为“employees”的自定义帖子类型,这是我与FacetWP(我们正在使用的插件)一起使用的查询。我们想按post\\u标题对员工进行排序。
<?php
return [
"post_type" => [
"employees"
],
"post_status" => [
"publish"
],
"orderby" => [
"post_title"
],
"order" => [
"ASC"
],
"posts_per_page" => "99"
];
这不起作用,我试着这样做:
<?php
return array(
"post_type" => "employees",
"post_status" => "publish",
"meta_key" => "post_title",
"orderby" => "meta_value",
"order" => "ASC",
"posts_per_page" => 99
);
这不会返回任何内容,因为“post\\u title”在postETA表中不存在。
也许有一个非常简单的解决方法,但我在这里迷失了方向。如何按post\\u标题对自定义帖子类型进行排序?
SO网友:user2812779
我找到了解决办法。当我接受我的第一个查询并这样做时:
<?php
return [
"post_type" => [
"employees"
],
"post_status" => [
"publish"
],
"orderby" => [
"post_title" => "ASC"
],
"posts_per_page" => "99"
];
排序正在工作。所以我替换了:
"orderby" => [
"post_title"
],
"order" => [
"ASC"
],
仅适用于:
"orderby" => [
"post_title" => "ASC"
],
这就成功了:)