• Resolved yuriyWP

    (@yuriywp)


    I have custom filed that I’m putting in my date like this 02/12/12
    which is mm/dd/yy how can I sort all my post’s bast on this date that I am manually making/imputing.
    In my loop i am doing this

    <?php $myinventory = new WP_Query('post_type=sermongs&showposts=10&meta_key=Date&orderby=meta_value&order=DESC'); ?>
    			<?php //replace inventory with whatever you called the post type ?>
    			<?php if($myinventory->have_posts()) : ?>
    			<?php while($myinventory->have_posts()) : $myinventory->the_post(); ?>
    
    <?php endwhile; ?>
    <?php endif; ?>

    Also my Custom Filed Template looks like this
    [Date]
    label = Example: —- 02-22-2009 —–
    type = textfield
    size = 20

    but its sorting only the 02 and 12 which is my month and date but its not getting to the year which is very important too. how can i make it look at all numbers including year?

    Can some one plz help me thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You could just change the posted on date and not use a custom field?

    You have DD-MM-YYYY
    29-02-2012
    29-02-2011
    26-02-2012
    26-02-2011
    25-02-2012
    25-02-2011

    You need to change the format YYYY-MM-DD year first.

    2012-02-29
    2012-02-26
    2012-02-25
    2011-02-29
    2011-02-26
    2011-02-25

    I would use: YYMMDD
    120229
    120226
    120225
    110229
    110226
    110225

    HTH

    David

    Thread Starter yuriyWP

    (@yuriywp)

    Well it does work if I use it like this yymmdd but I would like to use it like this dd-mm-yyyy so people could understand it much easier. Is there a way i could use it like that and how come its not doing it like this dd-mm-yyyy?

    Is there a way i could use it like that and how come its not doing it like this dd-mm-yyyy?

    Because it is a text sort and not a date sort!

    Not sure how you get around this one, why not just edit update the posted date and sort on that?

    David

    Thread Starter yuriyWP

    (@yuriywp)

    Thanks “Digital Raindrops” thats exactly what i did and it’s perfect solution for my problem…
    Here is the code for those that want to know it 🙂

    What I did is created a loop and in this loop i sorted all of my post’s by the date of its publishing… Now if you want to move your post either front of the list or back all you would need to do is change your publishing date in the post and it will sort it out by the post’s date and thats it.

    <?php //this is my custom loop and in here you can see how i did all. ?>
    <?php
    				$wp_query = new WP_Query(array('post_type'=>sermongs, 'paged' => $paged, 'posts_per_page'=>10,'orderby'=>Date, 'order'=>DESC));
    				?>
    				<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    
    <!-- This is were the stuff would go, that would be looped -->
    
    <!-- Then i am closing my loop with this php code -->
    <?php endwhile; ?>
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘How do i sort posts by a custom field Date?’ is closed to new replies.