Help on mysql query (select attachment ID)
-
Hello. Most of the time I found answers searching the forum, but not this time. Can anyone help me on this query.
What am i doing wrong?
<?php global $wpdb; $attachment_id = $wpdb->get_var(" SELECT $wpdb->posts.ID LEFT JOIN $wpdb->term_relationships ON $wpdb->posts.ID = $wpdb->term_relationships.object_id LEFT JOIN $wpdb->term_taxonomy ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id FROM $wpdb->posts WHERE $wpdb->posts.post_type='attachment' AND $wpdb->posts.post_title='header' AND $wpdb->term_taxonomy.taxonomy = 'category' AND $wpdb->term_taxonomy.term_id = '5' ORDER BY post_date DESC LIMIT 1"); ?><?php echo get_attachment_icon($attachment_id); ?>
What i’m trying to do is to put on the sidebar the latest post thumb (with “header” as image title) from an specific category. This is the first time i try to write my own query.
Thanks
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Help on mysql query (select attachment ID)’ is closed to new replies.