【发布时间】:2013-08-12 10:40:16
【问题描述】:
我正在使用以下查询来获取所有带有 post_type 'portfolio' 的帖子。
$args = array(
'posts_per_page' => -1,
'offset'=> 0,
'post_type' => 'portfolio'
);
$all_posts = new WP_Query($args);
$args 在哪里:
$args = array(
'posts_per_page' => -1,
'offset'=> 0,
'post_type' => 'portfolio',
'orderby' => 'up_count', //up_count is numeric field from posts table
'order' => DESC
);
这应该按 up_count 对结果进行排序。但事实并非如此。 codex for wp_query 没有明确说明使用自定义字段进行排序(或者我可能遗漏了什么?)。
这是我在调试 wp_query 请求时得到的查询。
SELECT ap_posts.* FROM ap_posts WHERE 1=1 AND ap_posts.post_type = 'portfolio' AND (ap_posts.post_status = 'publish' OR ap_posts.post_status = 'private') ORDER BY ap_posts.post_date DESC
编辑:up_count 是表 posts 表中的一个额外的 int 类型字段。
附:我正在使用 wordpress 版本。 3.5.2
【问题讨论】:
-
如果您编写自定义查询或者必须使用 wp_query 怎么办?
-
自定义查询可以是最后一个选项。我正在定制一个高级主题,如果我能用 wp_query 来做这件事,它将节省我大量的时间。