Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress ACF插件-如何按日期排序字段_Wordpress_Date_Advanced Custom Fields - Fatal编程技术网

Wordpress ACF插件-如何按日期排序字段

Wordpress ACF插件-如何按日期排序字段,wordpress,date,advanced-custom-fields,Wordpress,Date,Advanced Custom Fields,我正在使用高级自定义字段插件在自定义帖子中创建事件日期。我想在该日期前预订我的活动,但它不适合我: <div class="column one"> <?php $args = array( 'post_type' => 'formation', 'p

我正在使用高级自定义字段插件在自定义帖子中创建事件日期。我想在该日期前预订我的活动,但它不适合我:

<div class="column one">

                    <?php 

                        $args = array( 
                            'post_type'         => 'formation',
                            'posts_per_page'    => -1,
                            'post_status' => 'publish',
                            'meta_key'          => 'date_formation',
                            'orderby'           => 'meta_value_num',
                            'order'             => 'DESC'                   

                        ); 
                        $posts_query = new WP_Query( $args );

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

                        $presentation = get_field('date_formation');
                        $date_formation = mysql2date( 'j F Y ', $presentation);

                        $lieu = get_field('adresse_formation');
                    ?>

                            <div class="column one-third eventpost">
                                <div class="event-col">
                                 <?php  echo '<h4>'.$date_formation.''.$lieu.'</h4>'; ?> 
                                 <?php if( !is_single() ) {?><?php the_excerpt(); ?> <?php }else{ ?>
                                  <?php the_content(); ?>
                                  <?php } ?>
                                  <p><a href="<?php the_permalink(); ?>" rel="bookmark" title="En savoir plus">En savoir plus<i class="icon-right-open"></i></a></p>    
                                 </div>
                            </div>
                        <?php endwhile; wp_reset_query(); ?>

               </div>

试着用帕勒姆的溶液。您需要对其进行如下修改:

<div class="column one">
<?php
    function wpse_130954_orderby_fix($pieces){
    global $wpdb;
    $pieces['where']  .= " AND $wpdb->postmeta.meta_key = 'date_formation'";
    $pieces['orderby']  = "$wpdb->postmeta.meta_value DESC";
    return $pieces;
    }
    add_filter( 'posts_clauses', 'wpse_130954_orderby_fix', 20, 1 );
    $args = array(
        'post_type' => 'formation',
        'posts_per_page'=> -1,
        'post_status' => 'publish',
    ); 
    $posts_query = new WP_Query( $args );
    while ($posts_query->have_posts()) : $posts_query->the_post();
        $presentation = get_field('date_formation');
        $date_formation = mysql2date( 'j F Y ', $presentation);
        $lieu = get_field('adresse_formation');
?>
    <div class="column one-third eventpost">
        <div class="event-col">
            <?php echo '<h4>'.$date_formation.''.$lieu.'</h4>'; ?> 
            <?php if( !is_single() ) {?><?php the_excerpt(); ?><?php }else{ ?><?php the_content(); ?><?php } ?>
            <p><a href="<?php the_permalink(); ?>" rel="bookmark" title="En savoir plus">En savoir plus<i class="icon-right-open"></i></a></p>
        </div>
    </div>
    <?php endwhile; wp_reset_query(); ?>
    <?php remove_filter( 'posts_clauses', 'wpse_130954_orderby_fix', 20 ); ?>
</div>

我在我的template-formation.php中添加了代码,但不起作用“date\u formation”使用什么字段类型?它返回的值是多少?像这样:30.09.2015