I had posted this earlier on Stack Overflow, but couldn't get a positive result. I thought I should do this again.
<?php require_once 'news/wp-config.php';
$howMany = 0;
$query ="SELECT `ID`, `post_title`,'post_category', `guid`,SUBSTRING_INDEX(`post_content`, ' ', 100) AS `post_excerpt` FROM $wpdb->posts WHERE `post_status`= \"publish\" AND `post_type` = \"post\" AND post_category != \"1\" ";
$posts = $wpdb->get_results($query);
$posts = array_reverse($posts);
foreach($posts as $post)
{
if($howmany<10)
{
$link = $post->guid;
echo "<li><a target='_blank' href='$link'>$post->post_title</a></li>";
$howmany++;
}
}
?>
I want the above code not to display posts from Category 1. I think I have done everything right, but still I can't get the result that I want.
One more thing is if I even explicitly ask the query to display the posts from category 3 or 4, it doesn't happen. It ends up displaying posts from all categories.