Skip to main content
All code in code block
Source Link
Pieter Goosen
  • 55.4k
  • 23
  • 115
  • 209

All good, the very first suggestion from @Ammu was also working i. I needed to change the values from the array to match the statement here is the code:

global $wpdb; $cat_id = 10;

global $wpdb;
$cat_id = 10; 

$posts = $wpdb->get_results("SELECT 
ID, post_title AS title, post_excerpt AS excerpt FROM $wpdb->posts p
JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id)
JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
JOIN $wpdb->terms t ON (tt.term_id = t.term_id)
WHERE p.post_type='post'
AND p.post_status = 'publish'
AND tt.taxonomy = 'category'
AND t.term_id = $cat_id
ORDER BY post_date DESC LIMIT 4");

Thanks guys really appreciate

All good the very first suggestion from @Ammu was also working i needed to change the values from the array to match the statement here is the code:

global $wpdb; $cat_id = 10;

$posts = $wpdb->get_results("SELECT 
ID, post_title AS title, post_excerpt AS excerpt FROM $wpdb->posts p
JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id)
JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
JOIN $wpdb->terms t ON (tt.term_id = t.term_id)
WHERE p.post_type='post'
AND p.post_status = 'publish'
AND tt.taxonomy = 'category'
AND t.term_id = $cat_id
ORDER BY post_date DESC LIMIT 4");

Thanks guys really appreciate

All good, the very first suggestion from @Ammu was also working. I needed to change the values from the array to match the statement here is the code:

global $wpdb;
$cat_id = 10; 

$posts = $wpdb->get_results("SELECT 
ID, post_title AS title, post_excerpt AS excerpt FROM $wpdb->posts p
JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id)
JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
JOIN $wpdb->terms t ON (tt.term_id = t.term_id)
WHERE p.post_type='post'
AND p.post_status = 'publish'
AND tt.taxonomy = 'category'
AND t.term_id = $cat_id
ORDER BY post_date DESC LIMIT 4");
Source Link
Jono
  • 73
  • 2
  • 2
  • 10

All good the very first suggestion from @Ammu was also working i needed to change the values from the array to match the statement here is the code:

global $wpdb; $cat_id = 10;

$posts = $wpdb->get_results("SELECT 
ID, post_title AS title, post_excerpt AS excerpt FROM $wpdb->posts p
JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id)
JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
JOIN $wpdb->terms t ON (tt.term_id = t.term_id)
WHERE p.post_type='post'
AND p.post_status = 'publish'
AND tt.taxonomy = 'category'
AND t.term_id = $cat_id
ORDER BY post_date DESC LIMIT 4");

Thanks guys really appreciate