Support » Themes and Templates » Custom Queries

Viewing 4 replies - 1 through 4 (of 4 total)
  • <?php
    $cat_id = get_cat_ID('events');
      'cat' => $cat_id,
      'meta_value'=> 'theater',
      '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>
    wp_reset_query();  // Restore global post data stomped by the_post().

    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?


    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.


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Queries’ is closed to new replies.