Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can i retrive the actor birthday by Date.

How i add the date, i have a custom field with Calendar. enter image description here

Now is 20th ... how can i retrive the Actor By this day

I try this but it wont work

<?php // Get today's date in the right format
$todaysDate = date('md');
?>

<?php $loop = new WP_Query( array(
'post_type' => 'persoane',
'posts_per_page' =>5,
'meta_key' => 'data_nasterii',
'meta_compare' => '=',
'meta_value' => $todaysDate,
'orderby' => 'meta_value',
'order' => 'ASC'
) ); ?>

<?php while ($loop->have_posts()) : $loop->the_post(); ?>

The meta_key - data_nasterii is the custom field.

Ex: today is 20th Jan 2013

I want to retrivee all actors that are born in 20 th Jan , with the specification in (38 Years Old (2013-1975=38 years))

EX: 50 Cent - Today is his birthday. He is born on 20th Jan 1975 and he has 38 Years .

if anny body know's please post , it will be apreciate , when i found a solution myself i woud post here for others to see. Thanks.

share|improve this question
1  
What format are you storing your dates in? –  Joseph Jan 20 '13 at 0:06
add comment

1 Answer

up vote 0 down vote accepted

For this to work you need the date stored in the database to match the $todaysDate and it probably doesn't. If I am reading your somewhat confusing question correctly then you are storing dates like 20th Jan 2013 but you are matching it against a date that looks like 0120 (January 20). Even if you are are storing dates as a MySQL date, UNIX Timestamp, or as a somewhat more parsable string like 01-20-1975 it still isn't going to match your comparison string.

Your solution is to understand what your data looks like and to search accordingly. I'd recommend storing as a MySQL date or a UNIX timestamp. Either can be programmatically manipulated fairly easily. Without more information-- meaning a better question-- I don't know what else to say.

Based on additional information in a comment below:

Use meta_query instead of meta_compare.

$args = array(
  'post_type' => 'persoane',
  'posts_per_page' =>5,
    'meta_query' => array(
        array(
            'key' => 'data_nasterii',
            'value' => '__'.$todaysDate,
            'compare' => 'LIKE'
        )
    )
);
$loop = new WP_Query( $args );

Used with LIKE the underscore matches exactly one character so if your dates are consistently a two-digit year, two-digit-month, and two-digit day and if WP_Query passes the _ through unchanged (I have never tried. I don't know.) that should match "any two characters followed by your generated date". That is not going to be a very efficient query but given your data structure I think that is what you have to go with.

share|improve this answer
    
the date is store like this...yymmdd .. anny help? This format will determin the value saved to the database and returned via the API "yymmdd" is the most versatile save format. –  Batman Jan 20 '13 at 22:32
    
i tried this but it do not work –  Batman Feb 11 '13 at 20:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.