<?php
$cat_id = get_cat_ID('events');
$args=array(
'cat' => $cat_id,
'meta_value'=> 'theater',
'meta_key'=>'type_or_whatever_your_key_is_here',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo 'List of Posts';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
Related:
Stepping Into Template Tags
Stepping Into Templates
Template Hierarchy
Great, thanks for that MichaelH!
That method is quite different from the method I ended up using (which was straight from the wpdb Class function ref. page linked above)
$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
WHERE wposts.ID = wpostmeta.post_id
AND wpostmeta.meta_key = 'event_type'
AND wpostmeta.meta_value = '$eventType'
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
ORDER BY wposts.post_date DESC";
$pageposts = $wpdb->get_results($querystr, OBJECT);
Your method looks nicer though. Are there particular reasons for using one or the other of these two different methods?
a|x
While the wpdb class is nice, and necessary at times, using query_posts decreases the chances future database changes will affect your customizations.
Ah, OK. Thanks for that.
I’ll give it a go.
a|x