I currently have the following code that does exactly what I want it to do. It lists all of the custom post type “programs” and excludes listing the post if the custom field program_flags (multiple checkbox options for this custom field) has the option Gas checked off:
// just return them all
global $wpdb, $post;
$sql = $wpdb->prepare("SELECT ID FROM wp_posts AS p WHERE post_type=%s AND post_status='publish' AND NOT EXISTS ( SELECT post_id FROM wp_postmeta AS pm WHERE meta_key = %s AND meta_value = %s AND p.ID = pm.post_id) ORDER BY p.post_title ASC ", 'program', 'program_flags', 'Gas');
$records = $wpdb->get_results( $sql );
if(!empty($records)){
foreach( $records as $record ) {
$post = get_post( $record->ID );
$l.= "<div class='program-item'>";
$l.= "<div class='program-item-image'><a href='".get_permalink($post->ID)."'>". get_the_post_thumbnail($post->ID, 'thumbnail')."</a></div>";
$l.= "<div class='program-item-title'><a href='".get_permalink($post->ID)."'>".get_the_title($post->ID)."</a></div>";
$l.= "<div class='program-item-content'>".get_the_excerpt()."</div>";
$l.= "<div style='clear:both;'></div>";
$l.= "</div>";
}
}
I would like the following code updated to be set up like the code above, but also include the related school options. Please help.
<?php
// no show the results of the search
global $more; // Declare global $more (before the loop).
$more = 0; // Set (inside the loop) to display content above the more tag.
$l='';
query_posts(array('posts_per_page'=>'-1', 'post_type'=>'program', 'orderby'=>'title','order'=>'asc', 'meta_key'=>'related_school','meta_value'=>$post->ID ));
if ( have_posts() ) : while ( have_posts() ) : the_post();
$l.= "<div class='program-item'>";
$l.= "<div class='program-item-image'><a href='".get_permalink($post->ID)."'>". get_the_post_thumbnail($post->ID, 'thumbnail')."</a></div>";
$l.= "<div class='program-item-title'><a href='".get_permalink($post->ID)."'>".get_the_title($post->ID)."</a></div>";
$l.= "<div class='program-item-content'>".get_the_excerpt()."</div>";
$l.= "<div style='clear:both;'></div>";
$l.= "</div>";
endwhile; else:
endif;
//Reset Query
wp_reset_query();
if($l){
echo $l;
} else {
echo "<h2>Sorry, no results matched your search criteria. Please check and try again.</h2>";
}
?>