您好,我想在WordPress中显示自定义查询中的特定类别。我的代码运行良好,它获得了最新的4篇帖子,但我现在想要的是检索一个特定的类别。我的代码如下,谢谢:
global $wpdb;
$posts = $wpdb->get_results(\'SELECT ID, post_title AS title, post_excerpt AS excerpt FROM \'.$wpdb->posts.\' WHERE post_type = "post" AND post_status = "publish" ORDER BY post_date DESC LIMIT 4\');
这是我的完整代码:
global $wpdb;
$posts = $wpdb->get_results(\'SELECT ID, post_title AS title, post_excerpt AS excerpt FROM \'.$wpdb->posts.\'
WHERE post_type = "post" AND post_status = "publish" ORDER BY post_date cat = "category_id" DESC LIMIT 4\');
$items = array();
foreach ($posts as $post) {
$item = array();
$item[\'title\'] = get_the_title($post->ID);
$item[\'url\'] = get_permalink($post->ID);
$item[\'desc\'] = $post->excerpt;
$item[\'image\'] = wp_get_attachment_url( get_post_thumbnail_id($post->ID));
$item[\'thumb\'] = get_post_meta($post->ID, \'Thumbnail\', true);
$items[] = $item;
}
return $items;
现在,我想添加最终输出pout,请参见下面的代码:
阅读更多信息