Support

Account

Home Forums Front-end Issues get all posts in custom post type by ACF field value Reply To: get all posts in custom post type by ACF field value

  • meta_query needs to be a nested array

    either

    
    'meta_query' => array(
      array(
        'key' => 'program_id',
        'value' => '5317',
        'compare' => 'LIKE'
      )
    ),
    

    or

    
    'meta_query' => [
      [
        'key' => 'program_id',
        'value' => '5317',
        'compare' => 'LIKE'
      ]
    ],
    

    @trisham the second way is a shorthand that was added in PHP 5.4, similar to how arrays can be declared in JavaScript, which I prefer not to use. Mostly because my IDE does not understand it and shows a syntax error that prevents me from seeing real syntax errors. Besides, it only saves typing out “array” which I do instinctively and would save me what? Less than a second? I also find it a lot less clear when reviewing code.