我需要列出每年完成的(meta\\u值)项目(meta\\u值),如下所示:
2006年-项目1-项目2。。。
2005年项目3。。。
我发现(here) 我要处理的一段很棒的代码:
<?php // List posts by a Custom Field\'s values
$meta_key = \'year\'; // The meta_key of the Custom Field
$sql = "
SELECT p.*,m.meta_value
FROM $wpdb->posts p
LEFT JOIN $wpdb->postmeta m ON (p.ID = m.post_id)
WHERE p.post_type = \'post\'
AND p.post_status = \'project\'
AND m.meta_key = \'$meta_key\'
ORDER BY m.meta_value, p.post_date DESC
";
$rows = $wpdb->get_results($sql);
if ($rows) {
foreach ($rows as $post) {
setup_postdata($post);
if ($post->meta_value != $current_value) {
echo "<h3>$post->meta_value</h3>";
$current_value = $post->meta_value;
}
// Put code here to display the post
the_title();
}
}
?>
但我仍然有(1)对代码的进一步要求和(2)代码存在问题,这是:我需要用另一个meta\\u键(键状态:valuecompleted)过滤查询。
我使用WPML,帖子列表同时显示帖子及其翻译(应该只获取当前语言的帖子)