• Resolved ventatto

    (@ventatto)


    Hi,

    I would like to do the following except I want to ignore the year. In other words, I want to order by month and then by day since it will eventually result in displaying a list to wish a happy birthday to people during a certain period.

    
    $args = array(
    	'post_type' => array( 'player'),
    	'numberposts' => -1,
    	'posts_per_page' => -1,
    	'orderby' => 'date',
    	'order' => 'ASC',
    );
    

    I saw some possibilities with meta queries but I have no idea what to set as a meta_key and how to deal with that. I was also wondering if there was no easier possibility than using meta queries.

    If I was not clear enough, here is the order I would like :
    – Bob, 22/11/1960
    – John, 30/11/1957
    – Tim, 01/12/1959

    while my current code gives :
    – John, 30/11/1957
    – Tim, 01/12/1959
    – Bob, 22/11/1960

    Thanks for your help !

Viewing 16 replies (of 16 total)
  • Thread Starter ventatto

    (@ventatto)

    I tried again several times differently but still the same issue…

    I eventually looked for another way to address the problem and found a reordering after doing get_posts($posts). Here it is :

    function cmp_birthday($a, $b)
    {
        $month1 = date('m', strtotime($a->post_date));
        $month2 = date('m', strtotime($b->post_date));
        $cmp = strcasecmp($month1, $month2);
        if ($cmp == 0)
        {
            $day1 = date('d', strtotime($a->post_date));
            $day2 = date('d', strtotime($b->post_date));
            return strcasecmp($day1, $day2);
        }
        else
            return $cmp;
    }
    usort($posts, "cmp_birthday");

    I really want to thank you for the time you spent trying to find a solution for me.

    Best regards.

Viewing 16 replies (of 16 total)
  • The topic ‘parse_query() orderby date ignoring year’ is closed to new replies.