Thursday, October 13, 2022
HomeWordPress Developmentsuperior customized fields - Foreach loop returns string(0) "" string(0) ""

superior customized fields – Foreach loop returns string(0) “” string(0) “”


Here is an output of an array:

Array(1) {
  [0]=>
  array(15) {
    ["ID"]=>
    int(311)
    ["key"]=>
    string(19) "group_632beaa7009aa"
    ["title"]=>
    string(4) "Check"
    ["fields"]=>
    array(0) {
    }
    ["location"]=>
    array(1) {
      [0]=>
      array(1) {
        [0]=>
        array(3) {
          ["param"]=>
          string(9) "post_type"
          ["operator"]=>
          string(2) "=="
          ["value"]=>
          string(4) "check"
        }
      }
    }
    ["menu_order"]=>
    int(0)
    ["position"]=>
    string(6) "regular"
    ["style"]=>
    string(7) "default"
    ["label_placement"]=>
    string(3) "prime"
    ["instruction_placement"]=>
    string(5) "label"
    ["hide_on_screen"]=>
    array(13) {
      [0]=>
      string(9) "permalink"
      [1]=>
      string(11) "the_content"
      [2]=>
      string(7) "excerpt"
      [3]=>
      string(10) "dialogue"
      [4]=>
      string(8) "feedback"
      [5]=>
      string(9) "revisions"
      [6]=>
      string(4) "slug"
      [7]=>
      string(6) "writer"
      [8]=>
      string(6) "format"
      [9]=>
      string(15) "page_attributes"
      [10]=>
      string(14) "featured_image"
      [11]=>
      string(4) "tags"
      [12]=>
      string(15) "send-trackbacks"
    }
    ["active"]=>
    bool(true)
    ["description"]=>
    string(0) ""
    ["show_in_rest"]=>
    int(0)
    ["_valid"]=>
    bool(true)
  }
}

And that is the foreach loop

$post_id = get_the_ID();

$cpt_groups = acf_get_field_groups([
    'post_id' => $post_id,
]);

$cpt_group_id = '';
foreach( $cpt_groups as $cpt_group ) {
    $cpt_group_id .= $cpt_group['ID'];
}

var_dump($cpt_group_id);

I’ve no thought why it returns int(311) and string(0) “” string(0) “”

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments