WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multi query array() (2 posts)

  1. Beee
    Member
    Posted 1 year ago #

    I am working on a site which lists models.
    For every model I create a page, which have several custom fields, one of them is dob for the date of birth.
    This value is defined as mm/dd/yyyy.

    I want to create a query which retrieves all the pages where the dob mm/dd/yyyy gets stripped to mm/dd and then compared to the current date to see if it is today.

    I use the following code/query. There's 1 disadvantage; when there are 0 results the header and

      still shows.

      Anybody have a tip ?

      $args = array(
      		'post_type' 	=> 'page',
      		'post_parent' => '2',
      		'orderby' 		=> 'title',
      		'order' 			=> 'ASC',
      		'showposts' 	=> '-1',
      		'meta_key' 		=> 'dob'
      	);
      	$bday = new WP_Query($args);
      	if ($bday->have_posts()) :
      	echo '<aside id="birthdays" class="widget">';
      	echo '<h5>Today\'s birthdays</h5>';
      	echo '<ul>';
      	while ($bday->have_posts()) : $bday->the_post();
      		$dob = get_post_meta($post->ID, 'dob', true);
      		$bdate = substr($dob, 0, strrpos($dob, '/'));
      		$today = date('m/d');
      		if ( $today == $bdate )
      		{ ?>
      					<li class=""><a href="<? the_permalink(); ?>" title="See all galleries from the birthday babe"><? the_title(); ?></a></li>
      <? }
      	endwhile;
      	echo '</ul>';
      	echo '</aside>';
      	else : endif;
    • Beee
      Member
      Posted 1 year ago #

      Fixed it (I think)...
      For those who care to know...

      $args = array(
      		'post_type' 	=> 'page',
      		'post_parent' => '2',
      		'orderby' 		=> 'title',
      		'order' 			=> 'ASC',
      		'showposts' 	=> '-1',
      		'meta_key' 		=> 'dob'
      	);
      	$bday = new WP_Query($args);
      	if ($bday->have_posts()) :
      		echo '<aside id="birthdays" class="widget">';
      		echo '<ul>';
      		$counter = 0;
      	while ($bday->have_posts()) : $bday->the_post();
      		$dob = get_post_meta($post->ID, 'dob', true);
      		$bdate = substr($dob, 0, strrpos($dob, '/'));
      		// $today = date('m/d');
      		$today = "03/14";
      		if ( $today == $bdate )
      		{
      			$counter++;
      			if ( $counter == 1 )
      			{
      ?>
      					<li class=""><h5>Today's birthdays</h5></li>
      					<li class=""><a href="<? the_permalink(); ?>" title="See all galleries from the birthday babe"><? the_title(); ?></a></li>
      <?
      			} // endif counter == 1
      			if ( $counter > 1 )
      			{
      ?>
      					<li class=""><a href="<? the_permalink(); ?>" title="See all galleries from the birthday babe"><? the_title(); ?></a></li>
      <?
      			} // endif counter > 1
      		} // endif (today == bdate)
      	endwhile;
      	echo '</ul>';
      	echo '</aside>';
      	else : endif;

    Topic Closed

    This topic has been closed to new replies.

    About this Topic