Hello. I'm generally a n00b at strings of php, but I've built/tweaked a little bit of code here built to pull a list of posts from a custom post type while simultaneously highlighting the current post title if you're on that page. The query works, but in order to get it to work I have two $query = new WP_Querys going on, and I'm trying to combined them, just to make everything a little cleaner.
$query = new WP_Query('category_name=' . $category->locations);
// Workaround for Cateogry Variable
$query = new WP_Query( array( 'post_type' => 'locations', 'orderby' => 'name', 'order' => 'ASC') );
Any suggestions? (FULL code below)
<ul>
<?php
$IDOutsideLoop = $post->ID;
while( have_posts() ) {
the_post();
foreach( ( get_the_category() ) as $category )
$query = new WP_Query('category_name=' . $category->locations);
// Workaround for Cateogry Variable
$query = new WP_Query( array( 'post_type' => 'locations', 'orderby' => 'name', 'order' => 'ASC') );
if( $query ) {
while ( $query->have_posts() ) {
$query->the_post(); ?>
<li<?php print ( is_single() && $IDOutsideLoop == $post->ID ) ? ' class="current-locale"' : ''; ?> id="post-<?php the_ID(); ?>" <?php post_class(); ?> >
<a>"><?php the_title(); ?></a>
<?php
}
}
} wp_reset_postdata();
?>
</ul>
Thanks in advance!