Title: FinDes's Replies | WordPress.org

---

# FinDes

  [  ](https://wordpress.org/support/users/findes/)

 *   [Profile](https://wordpress.org/support/users/findes/)
 *   [Topics Started](https://wordpress.org/support/users/findes/topics/)
 *   [Replies Created](https://wordpress.org/support/users/findes/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/findes/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/findes/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/findes/engagements/)
 *   [Favorites](https://wordpress.org/support/users/findes/favorites/)

 Search replies:

## Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)

 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Custom Meta Queries](https://wordpress.org/support/topic/custom-meta-queries/)
 *  Thread Starter [FinDes](https://wordpress.org/support/users/findes/)
 * (@findes)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/custom-meta-queries/#post-4999893)
 * I am closer, with the code below, the Upcoming events show in the first loop,
   but the past events query duplicates the first upcoming event 4 times.
 *     ```
       <h1>2013-14 Concert Season</h1>
       		<?php
       			$today = date('Ymd');
       			$args1 = array(
       				'type' => 'post',
       				'category_slug' => 'Featured1314',
       				'meta_key' => 'concert_date',
       				'meta_query' => array(
       					'relation' => 'AND',
       						array(
       							'key' => 'concert_date',
       							'value' => $today,
       							'compare' => '>='
       						)
       					),
       				'orderby' => 'meta_value_num',
       				'order' => 'ASC'
       				);
       			$upcoming_query = new WP_Query($args1);
       			if( $upcoming_query->have_posts() ) { ?>
       		<h2>Upcoming Concerts</h2>
       		<ul><?php while ( $upcoming_query->have_posts() ) { $upcoming_query->the_post(); ?>
       			<li id="post-<?php the_ID(); ?>"><h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1><p><?php the_excerpt() ?></p></li>
       		<?php } }?>
       		</ul>
       		<?php
       			rewind_posts();
       			$today = date('Ymd');
       			$args2 = array(
       				'type' => 'post',
       				'category_slug' => 'Featured1314',
       				'meta_key' => 'concert_date',
       				'meta_query' => array(
       					'relation' => 'OR',
       						array(
       							'key' => 'concert_date',
       							'value' => $today,
       							'compare' => '<'
       						)
       					),
       				'orderby' => 'meta_value_num',
       				'order' => 'ASC'
       				);
       			$past_query = new WP_Query($args2);
       			if( $past_query->have_posts() ) {?>
       			<h2>Past Concerts</h2>
       		<ul><?php while ( $past_query->have_posts() ) { $past_query->next_post(); ?>
       			<li id="post-<?php the_ID(); ?>"><h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1><p><?php the_excerpt() ?></p></li>
       		<?php } }?>
       		</ul>
       ```
   
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [Custom Meta Queries](https://wordpress.org/support/topic/custom-meta-queries/)
 *  Thread Starter [FinDes](https://wordpress.org/support/users/findes/)
 * (@findes)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/custom-meta-queries/#post-4999845)
 * I tried this and it netted the same results as before.
 *   Forum: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
   
   In reply to: [list posts in sidebar with matching custom fields](https://wordpress.org/support/topic/list-posts-in-sidebar-with-matching-custom-fields/)
 *  Thread Starter [FinDes](https://wordpress.org/support/users/findes/)
 * (@findes)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/list-posts-in-sidebar-with-matching-custom-fields/#post-1202555)
 * Here is what I have so far, but there is something wrong with my query…
 *     ```
       <?php
       echo("<ul>");
       $ID = get_the_ID();
       echo("<li>ID = " . $ID . "</li>");
   
       $title = get_post_custom_values('Title', $ID);
       $season = get_post_custom_values('Season', $ID);
   
       echo("<li>Title = " . $title[0] . "</li>");
       echo("<li>Season = " . $season[0] . "</li>");
       echo("</ul>");
   
        $querystr = "
           SELECT wposts.*
           FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
           WHERE wposts.ID = wpostmeta.post_id
           AND wpostmeta.meta_key = $title[0]
           AND wpostmeta.meta_key = $season[0]
           AND wposts.post_status = 'publish'
           AND wposts.post_type = 'post'
           ORDER BY wposts.post_date DESC
        ";
   
        $pageposts = $wpdb->get_results($querystr, OBJECT);
   
        ?>
   
       <ul>
       <?php if ($pageposts): ?>
       <?php foreach ($pageposts as $post): ?>
       <?php setup_postdata($post); ?>
       <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
           <?php the_title(); ?></a></li>
       <?php endforeach; ?>
       <?php else : ?>
       <li>Sorry no other episodes this season, yet.</li>
       <?php endif; ?>
       </ul>
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)