admin管理员组

文章数量:1122832

I have a Custom Post Type 'Production' with 'Tourdates' as a repeaterfield (using Advanced Custom Field plugin). Tourdates have a 'Date & Time Picker 'field named 'Playdate'.

I would now like to display (in a list) all Playdates of all Productions sorted chronologically.

My current query displays the posts like this:

  • 09/04/2017 (Production x)
  • 28/12/2017 (Production y)
  • 07/04/2017 (Production x)
  • 11/04/2017 (Production x)
  • 31/04/2017 (Production y)
  • 14/04/2017 (Production y)

But I'm looking to get them displayed like this:

  • 07/04/2017 (Production x)
  • 09/04/2017 (Production x)
  • 11/04/2017 (Production x)
  • 14/04/2017 (Production y)
  • 31/04/2017 (Production y)
  • 28/12/2017 (Production y)

My code:

    $args = array(
    'numberposts'           => -1,
    'post_status'           => 'publish',
    'post_type'                 => 'productie',
    'suppress_filters'  => false,
);

$the_query = new WP_Query( $args );

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

    $productienaam = get_the_title();

        if( have_rows('tourdata') ):
        while ( have_rows('tourdata') ) : the_row();

                $speeldatum = get_sub_field('speeldatum');
                $the_ID = get_the_ID();

                $productie[$speeldatum][$the_ID]['speeldatum'] = $speeldatum;
                $productie[$speeldatum][$the_ID]['name'] = $productienaam;
            endwhile;
      endif;

    endwhile;
endif;

// $speeldatum = date("Ymd");

asort($productie);

foreach ($productie as $key_day => $row_day){
  if ($key_day > date("Ymd")) {
    foreach ($row_day as $key_productie => $row_productie){
        $productie_name = $row_productie['name'];
      $productie_date = $row_productie['speeldatum'];
      echo $productie_date .' : '. $productie_name .'<br />';
    }
  }}

I have a Custom Post Type 'Production' with 'Tourdates' as a repeaterfield (using Advanced Custom Field plugin). Tourdates have a 'Date & Time Picker 'field named 'Playdate'.

I would now like to display (in a list) all Playdates of all Productions sorted chronologically.

My current query displays the posts like this:

  • 09/04/2017 (Production x)
  • 28/12/2017 (Production y)
  • 07/04/2017 (Production x)
  • 11/04/2017 (Production x)
  • 31/04/2017 (Production y)
  • 14/04/2017 (Production y)

But I'm looking to get them displayed like this:

  • 07/04/2017 (Production x)
  • 09/04/2017 (Production x)
  • 11/04/2017 (Production x)
  • 14/04/2017 (Production y)
  • 31/04/2017 (Production y)
  • 28/12/2017 (Production y)

My code:

    $args = array(
    'numberposts'           => -1,
    'post_status'           => 'publish',
    'post_type'                 => 'productie',
    'suppress_filters'  => false,
);

$the_query = new WP_Query( $args );

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

    $productienaam = get_the_title();

        if( have_rows('tourdata') ):
        while ( have_rows('tourdata') ) : the_row();

                $speeldatum = get_sub_field('speeldatum');
                $the_ID = get_the_ID();

                $productie[$speeldatum][$the_ID]['speeldatum'] = $speeldatum;
                $productie[$speeldatum][$the_ID]['name'] = $productienaam;
            endwhile;
      endif;

    endwhile;
endif;

// $speeldatum = date("Ymd");

asort($productie);

foreach ($productie as $key_day => $row_day){
  if ($key_day > date("Ymd")) {
    foreach ($row_day as $key_productie => $row_productie){
        $productie_name = $row_productie['name'];
      $productie_date = $row_productie['speeldatum'];
      echo $productie_date .' : '. $productie_name .'<br />';
    }
  }}
Share Improve this question edited Sep 6, 2017 at 7:04 zuperuser asked Sep 5, 2017 at 20:53 zuperuserzuperuser 111 silver badge3 bronze badges 2
  • this actually have nothing to do with wordpress or ACF, just have an array with the information based on dates and sort it by the dates before stating output – Mark Kaplun Commented Sep 6, 2017 at 8:00
  • Hi Mark, thank you for your suggestion. Could you point me in the right direction to store the information in an array and sort it by the dates? – zuperuser Commented Sep 6, 2017 at 18:08
Add a comment  | 

1 Answer 1

Reset to default 0

I think I succeeded in making the array and sorting it by date (see var_dump)

 
array(575) {
  [320]=>
  array(10) {
    ["Speeldatum"]=>
    string(19) "2015-01-30 12:00:00"
    ["Productienaam"]=>
    string(28) "THE DOG DAYS ARE OVER (2014)"
    ["Makernaam"]=>
    string(11) "Jan Martens"
    ["Locatienaam2"]=>
    string(10) "toneelhuis"
    ["Stadnaam"]=>
    string(9) "ANTWERPEN"
    ["Landnaam"]=>
    string(2) "BE"
    ["Festivalnaam"]=>
    string(18) "antwerpse kleppers"
    ["Onderdeelvandezegripeveningnaam"]=>
    string(38) "antwerpse kleppers / bourla schouwburg"
    ["Extranaam"]=>
    string(0) ""
    ["Ticketlink"]=>
    string(0) ""
  }
  [510]=>
  array(10) {
    ["Speeldatum"]=>
    string(19) "2015-02-05 12:00:00"
    ["Productienaam"]=>
    string(23) "SWEAT BABY SWEAT (2011)"
    ["Makernaam"]=>
    string(11) "Jan Martens"
    ["Locatienaam2"]=>
    string(20) "cultuurcentrum diest"
    ["Stadnaam"]=>
    string(5) "DIEST"
    ["Landnaam"]=>
    string(2) "BE"
    ["Festivalnaam"]=>
    string(28) "internationale tanzmesse nrw"
    ["Onderdeelvandezegripeveningnaam"]=>
    string(13) "le grand bain"
    ["Extranaam"]=>
    string(0) ""
    ["Ticketlink"]=>
    string(0) ""
  }
  [434]=>
  array(10) {
    ["Speeldatum"]=>
    string(19) "2015-02-07 12:00:00"
    ["Productienaam"]=>
    string(13) "VICTOR (2013)"
    ["Makernaam"]=>
    string(11) "Jan Martens"
    ["Locatienaam2"]=>
    string(24) "théâtre de la bastille"
    ["Stadnaam"]=>
    string(6) "PARIJS"
    ["Landnaam"]=>
    string(2) "FR"
    ["Festivalnaam"]=>
    string(25) "les printemps de sévelin"
    ["Onderdeelvandezegripeveningnaam"]=>
    string(13) "le grand bain"
    ["Extranaam"]=>
    string(13) "(premiere FR)"
    ["Ticketlink"]=>
    string(0) ""
  }
  ... and so on
}

But how can I now display the results?

I have this:

$stack[] = array(
    'Speeldatum' => $speeldatumunix,
    'Productienaam' => $productienaam,
    'Makernaam' => $makernaam,
    'Locatienaam2' => $locatienaam2,
    'Stadnaam' => $stadnaam,
    'Landnaam' => $landnaam,
    'Festivalnaam' => $festivalnaam,
    'Onderdeelvandezegripeveningnaam' => $onderdeelvandezegripeveningnaam,
    'Extranaam' => $extranaam,
    'Ticketlink' => $ticketlink
    );

asort($stack);
    

Then did this:

    foreach( $stack as $key => $speeldatumunix ) {
        echo '<ul>';
        foreach( $speeldatumunix as $attribute => $value ) {
            echo '<li>' . $attribute . ':' . $value . '</li>';
        }
        echo '</ul>';
    }

It displays the right stuff, in a list. So far so good.

BUT:

How can I get the values in a separate line so I can style them?
So instead of

    echo $attribute . ':' . $value;

I would need something like this:

    echo '<p class="name">'.$productienaam.'</p>';

This is obviously not correct. I guess my question now is how to write the syntax?

本文标签: loopQuery posts and display all dates in repeater field in chronological order