更改日期格式高级自定义字段wordpress

时间:2013-02-20 11:41:05

标签: javascript wordpress custom-fields date-formatting

您好我正在使用wordpress的高级自定义字段,我正在尝试修复日期显示:24/01/201而不是01/24/2013

我一直在看ACF网站,但我似乎无法找到它为什么这样做。

请附上我的代码:)

<?php
 // start query
                       $query_args = array(

                           // number of featured items to show
                           'posts_per_page' => '-1',
                           'post_type' => 'product',


                       );

                       $args = array(
                            'meta_key' => 'time_&_date',
                            'orderby' => 'meta_value_num',
                            'order' => 'DESC'
                        );

                        $the_query = new WP_Query( $args );

                        while ( $the_query->have_posts() ) : $the_query->the_post();

                            $date = DateTime::createFromFormat('Ymd', get_field('time_&_date'));
                            echo $date->format('M d, Y');
                        endwhile;



                       // start loop
                       $wp_query = new WP_Query($query_args);
                       if ($wp_query->have_posts()) {
                       echo '<ul class="eventslist">';


                        echo '</br>';
                        echo '</br>';
                           // start while
                           while($wp_query->have_posts()) : $wp_query->the_post();
                           $_product = new jigoshop_product(get_the_ID());
                           echo '<li>';
                               // Event container
                               echo '<a href="'.get_permalink().'">';

                              // Event title
                              echo '<div class="loop_title lightlinksnounderline"> <span>&bull;</span>' . the_title('','',false);


                              echo '</a>';
                              echo '</div>';

                              echo '<h3 class="field_title_loop">Date &amp Time: '; the_field('time_&_date');


                                    echo '</h3>';
                                     echo '<div class="cart_button">' ; do_action('jigoshop_after_shop_loop_item', $post, $_product );
                                        echo '</div>';

                           echo '</li>';
                           echo '<div class="price_cart">' ; do_action('jigoshop_after_shop_loop_item_title', $post, $_product);
                                echo '</div>';
                           echo '</br>';



                            echo '<div class="cart_line">';
                                     echo '</div>';


                           // end while
                           endwhile;
                       echo '</ul>';

                       // end loop
                       // reset query
                       wp_reset_query();
                       }

    ?>  

1 个答案:

答案 0 :(得分:0)

你的$ date-&gt;格式不应该是(d M Y)吗?