I have the plugin "Advanced Custom Field"
I use this plugin to make a calendar. My post is order by date.
I have a field for date.
$date = get_field('start-date');
This code return: 20131123
<strong>How to French turned this date via a function?</strong>(Like that: 23 Novembre 2013)
At the moment I have this code that shows me the date in this format: 23/11/2013
$date = get_field('start-date');
// $date = 19881123 (23/11/1988)
// extract Y,M,D
$y = substr($date, 0, 4);
$m = substr($date, 4, 2);
$d = substr($date, 6, 2);
// create UNIX
$time = strtotime("{$d}-{$m}-{$y}");
// format date
$start_date = date('d/F/Y', $time);
I made a code to display my event (in chronological order).
<strong>How to display only upcoming event ?</strong>(the date of the event is greater than today's date)
For now i have that:
<?php
query_posts( array('post_type'=>'evenement','orderby'=>'menu_order','order'=>'ASC' ) );
?>
<?php while (have_posts()) : the_post(); ?>
<div class="event" id="<?php echo the_slug(); ?>">
<?php
$date = get_field('start-date');
// $date = 19881123 (23/11/1988)
// extract Y,M,D
$y = substr($date, 0, 4);
$m = substr($date, 4, 2);
$d = substr($date, 6, 2);
// create UNIX
$time = strtotime("{$d}-{$m}-{$y}");
// format date
$start_date = date('d/F/Y', $time);
$date2 = get_field('end-date');
// $date = 19881123 (23/11/1988)
// extract Y,M,D
$y = substr($date2, 0, 4);
$m = substr($date2, 4, 2);
$d = substr($date2, 6, 2);
// create UNIX
$time = strtotime("{$d}-{$m}-{$y}");
// format date
$end_date = date('d/m/Y', $time);
?>
<div class="img-event"><?php the_post_thumbnail('event'); ?></div>
<div class="overlay">
<div class="date"><a href="<?php the_permalink(); ?>"><?php echo $start_date; ?></a></div>
<div class="title-event"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
</div>
<div class="info-bottom">
<span class="hour"><?php echo the_field('start-hour'); echo "-";echo the_field('end-hour'); ?></span>
<span class="price"><?php echo the_field('prix'); ?></span>
<div class="clear"></div>
</div>
</div><!-- .event -->
<?php endwhile; ?>
Sébastien | French WordpressDesigner answers:
salut robin
ça fait plaisir de te voir ici :-)
pour transformer ta date en français
$date = get_field('start-date');
$y = substr($date, 0, 4);
$m = substr($date, 4, 2);
$d = substr($date, 6, 2);
setlocale(LC_TIME, "fr_FR");
$date = strtotime($d.'-'.$m.'-'.$y);
echo strftime("%e %B %G",$date);
et pour la requête
$current_date = date('Ymd');
$current_date = intval($current_date);
echo "<br>";
$args = array(
'post_type'=>'evenement',
'orderby'=>'meta_value_num' ,
'order'=>'DESC' ,
'meta_query'=> array(
array(
'key' => 'start-date',
'compare' => '>',
'value' => $current_date,
'type' => 'numeric'
)
)
);
query_posts( $args );
ce code va donc classer tes événements futurs dans l'ordre décroissant.
Normalement tu ne devrais pas avoir de problème.
Dis-moi si cette requête correspond bien à ton besoin.
Robin Ferrari comments:
Alléluia Sebastien t'es un géni !! ca joue pour mes deux questions
Arnav Joy answers:
try these two
<?php
$date = get_field('start-date');
setlocale(LC_ALL, 'fr_FR');
echo strftime("%d %B %Y", mktime($date)) . "\n";
echo gmstrftime("%d %B %Y", mktime($date)) . "\n";
?>
Arnav Joy comments:
try this
<?php
query_posts( array('post_type'=>'evenement','orderby'=>'meta_value_num' ,'order'=>'DESC' , 'meta_value' => time() ,'meta_compare' => '>=' ) );
?>
Robin Ferrari comments:
doesn't work... it's always return the same date ( 01 janvier 1970 )
Arnav Joy comments:
try this
<?php
$date = get_field('start-date');
setlocale(LC_ALL, 'fr_FR');
echo strftime("%d %B %Y", strtotime(($date))) . "\n";
echo gmstrftime("%d %B %Y", strtotime(mktime($date))) . "\n";
?>
Remy answers:
<blockquote>
How to French turned this date via a function?(Like that: 23 Novembre 2013)
</blockquote>
setlocale(LC_TIME, 'fr_FR' );
$start_date = strftime('%d %B %Y', $time);
This should give you the format you want for the date.
<blockquote>How to display only upcoming event ?(the date of the event is greater than today's date)</blockquote>
$date = date( 'Ymd');
$upcoming_query = new WP_Query( array(
'post_type' => 'evenement',
'orderby'=>'menu_order',
'order'=>'ASC',
'meta_query' => array(
array(
'key' => 'start-date',
'value' => $date,
'compare' => '>'
)
)
);
if ( $upcoming_query->have_posts() ) :
while( $upcoming_query->have_posts() ) : $upcoming_query->the_post;
// your code to display the results
endwhile;
endif;
You should remove the query_posts and replace it with this, and also move your display results code where I commented.