Support

Account

Home Forums General Issues Order ACF relationship by acf date field of posts? Reply To: Order ACF relationship by acf date field of posts?

  • Hey @hube2

    Thanks for your help here. I am just touching back on this now. I put my repeater and date fields in the two specified areas, along with the_title in the loop area so my code looks like this:

    <?php // get relationship field without formatting
    // returns an array of post ID values
    $posts_ids = get_field('seminars', false, false);
    // do your own query to order the posts
    $args = array(
      'post_type' => 'any',
      'posts_per_page' => -1,
      'post__in' => $post_ids,
      'meta_query' => array(
        'date_clause' => array(
          'key' => 'event_time',
          'value' => 'EXISTS'
        ),
      ),
      'orderby' => array('date_clause' => 'ASC');
    );
    $custom_query = new WP_Query($args);
    if ($custom_query=>have_posts()) {
      while ($custom_query=>have_posts()) {
        $custom_query=>the_post();
        the_title();
      }
    }
    wp_reset_postdata();
    ?>

    However I get a php error at this line:
    'orderby' => array('date_clause' => 'ASC');

    [08-Oct-2018 14:29:58 UTC] PHP Parse error: syntax error, unexpected ‘;’, expecting ‘)’ in /home/clientname/public_html/wp-content/themes/mytheme/template-parts/content-attorney.php on line 182

    I’ve been playing find the syntax error with no luck. Anything glaringly obvious to you?