admin管理员组

文章数量:1420145

i want to display posts every specific day like post should desplay in evry friday with meta key acf date picker

    <?php
      $todayName = date('l');
      $schedules = new WP_Query(array(
          'posts_per_page' => -1,
          'post_type' => 'serie',
          'meta_query' => array(
            'relation'    => 'AND',
            array(
              'key'   => 'status',
              'value'     => '1',
              'compare'   => '=',
            ),
            array(
              'key'   => 'release_date' ,
              'value'     => date('l'),
              'compare'   => '=',
              'type' => 'DATE',
            ),
          ),

      ));
    ?>

i want to display posts every specific day like post should desplay in evry friday with meta key acf date picker

    <?php
      $todayName = date('l');
      $schedules = new WP_Query(array(
          'posts_per_page' => -1,
          'post_type' => 'serie',
          'meta_query' => array(
            'relation'    => 'AND',
            array(
              'key'   => 'status',
              'value'     => '1',
              'compare'   => '=',
            ),
            array(
              'key'   => 'release_date' ,
              'value'     => date('l'),
              'compare'   => '=',
              'type' => 'DATE',
            ),
          ),

      ));
    ?>
Share Improve this question asked Jul 12, 2019 at 22:46 Kais BOKais BO 1 2
  • This might help 'compare' => 'LIKE', 'value' => '"'.date('l').'"'. Could you post is being saved to the db by that acf-field? – admcfajn Commented Jul 13, 2019 at 0:20
  • Yes my post saved with acf and I try this and it not working – Kais BO Commented Jul 14, 2019 at 0:27
Add a comment  | 

1 Answer 1

Reset to default 0

You need to specify the return-format of the acf-field as 'l'

& then modify your query as follows:

$todayName = date('l');
$schedules = new WP_Query([
  'posts_per_page' => -1,
  'post_type' => 'serie',
  'meta_query' => [
    'relation'    => 'AND',
    [
      'key'   => 'status',
      'value'     => '1',
      'compare'   => '=',
    ],
    [
      'key'   => 'release_date' ,
      'value' => '"'.todayName.'"',
      'compare' => 'LIKE', 
      // You might try this too. If you can use this instead of `LIKE` please do, because it's more efficient
      // 'value' => todayName,
      // 'compare' => '=',      
    ]
  ]
]);

本文标签: advanced custom fieldsDisplay posts every specific day