Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below thanks :
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');
And here is my full code :
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;
Now i want to add the final out pout see the code below :
" id="nav-fragment-"> "> " class="ui-tabs-panel" style=""> " alt="" /> " >" >Read more
wp_query
to fetch WordPress posts. Check this