ridesign
Member
Posted 9 months ago #
I want to run the query below but I do not get the guid when I echo it below.
$query = $wpdb->query("SELECT wp_posts.post_title, wp_posts.guid FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) WHERE 1=1 AND wp_term_taxonomy.taxonomy = 'category' AND wp_term_taxonomy.term_id IN ('26') AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 5");
echo $query->wp_posts.guid;
ridesign
Member
Posted 9 months ago #
With the above query I get the error message:
Fatal error: Call to a member function query() on a non-object in filename.php
Does the query need to be like this?
$query = $wpdb->query("SELECT $wpdb->posts.post_title, $wpdb->posts.guid FROM $wpdb->posts INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) WHERE 1=1 AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id IN ('26') AND $wpdb->posts.post_type = 'post' AND ($wpdb->posts.post_status = 'publish') ORDER BY $wpdb->posts.post_date DESC LIMIT 0, 5");
Wouldn't this also work?
<?php
$posts=get_posts('cat=26&showposts=0');
if ($posts) {
foreach($posts as $post) {
//setup_postdata($post);
echo $post->guid;
}
}
?>
You need to say:
global $wpdb;
before calling $wpdb->query
Mike T