Advertisement
chrisipeters

using get_results in WordPress

Mar 6th, 2012
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.67 KB | None | 0 0
  1. <?php
  2.              $eventpostid = $post->ID;
  3.           $eventslug = wp_get_post_terms( $eventpostid, 'album-categories' );
  4.           $eventvenueslug = $eventslug[0]->slug;
  5.           $eventvenuetitle = $eventslug[0]->name;
  6.            
  7.           $querydetails = "
  8.            SELECT posts.* FROM wp_posts posts
  9.            left join wp_term_relationships rel on posts.id = rel.object_id
  10.            left join wp_term_taxonomy tax on rel. term_taxonomy_id = tax.term_taxonomy_id
  11.            left join wp_terms terms on tax.term_id = terms.term_id
  12.            WHERE
  13.            (posts.post_type = 'gallery') AND
  14.            (post_status = 'Publish') AND
  15.            (tax.taxonomy = 'album-categories') AND
  16.            (terms.slug = '".$eventvenueslug."')
  17.          ";
  18.  
  19.          $pageposts = $wpdb->get_results($querydetails, OBJECT);
  20.          echo '<div style="height:0;width:0;overflow:hidden;visibility:hidden">';
  21.          echo '</div><ul id="cpAlbumCategory_thumbnails">';
  22.         if ($pageposts) {
  23.           foreach ($pageposts as $post):
  24.                   setup_postdata($post); ?>
  25.  
  26.                           <li>
  27.                               <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><img src=<?php echo get_template_directory_uri() ?>/timthumb.php?src=<?php echo max_get_image_path($post->ID, 'full') ?>&amp;h=58&amp;w=57&amp;q=80&amp;zc=1 /></a>
  28.                             </li>
  29.  
  30.             <?php endforeach;
  31.             echo '</ul><br class="clearfix" />';
  32.           } else {
  33.  
  34.             echo '<p style="padding:5px">No Photos have been added to this album yet.</p>';
  35.  
  36.            
  37.            
  38.         }
  39.  
  40.         wp_reset_query();
  41.  
  42.         ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement