按日期排序的多列阵

时间:2017-11-02 11:46:05

标签: php arrays wordpress sorting multidimensional-array

我正在使用WordPress和custom_post_type。 我有一个数组(PHP),我想按日期排序这个,但默认情况下按post_id排序:

首先,我有一个SQL查询来从custom_post_type加载我的帖子。 对于每个帖子,如果开始日期>当前日期:

global $wp_query;
$args = array(
    'posts_per_page' => '9999999',
    'orderby' => 'event_start_date',
    'post_type'=> 'ai1ec_event',
    'events_categories' => 'events',
    'order' => 'DESC',
    'post_status' => 'publish'
);
$the_query = new WP_Query( $args );
$tabId = array();

if ( $the_query->have_posts() ) {
    while( $the_query->have_posts() ) {
        $the_query->the_post();
        global $post;
        $idEvent = $post->ID;

$sql = "SELECT * FROM og2rm_ai1ec_events WHERE post_id = ".$idEvent.";";
$results = $wpdb->get_results($sql);

foreach($results as $event)
{
    $start_date = $event->start;
    $end_date = $event->end;
    $heure = date("Y-m-d", $event->start);
    $currentDate = date("Y-m-d");
    $todayStr = strtotime ($currentDate);
    $lieu = $event->address;
    $rue = $event->venue;

    if($start_date > $todayStr){
        $a++;
        $tabId[$idEvent] = array('debut'=>$start_date,"lieu"=>$lieu,"rue"=>$rue,"fin"=>$end_date);
        }
    }

$tabId[$idEvent] = array('debut'=>$start_date,"lieu"=>$lieu,"rue"=>$rue,"fin"=>$end_date);

/******* echo <pre> $tabId : *******/

[21379] => Array
    (
        [debut] => 1510336800
        [lieu] => Example
        [rue] => Example
        [fin] => 1510340400
    )

[21376] => Array
    (
        [debut] => 1510268400
        [lieu] => Example
        [rue] => Example
        [fin] => 1512255600
    )

[21375] => Array
    (
        [debut] => 1511616600
        [lieu] => Example
        [rue] => Example
        [fin] => 1511620200
    )

[21372] => Array
    (
        [debut] => 1511530200
        [lieu] => Example
        [rue] => Example
        [fin] => 1511533800
    )

现在,我做了另一个foreach来显示我的帖子但是按ID显示而不是按日期显示。

我尝试过array_multisort或ksort / sort byt不起作用。

有什么想法吗?

感谢/

0 个答案:

没有答案