'wordpress acf repeater mapping in custom field post not working
After a long search on the net, my code didn't come up with what I wanted. I with wordpress and acf , the purpose of the function is to return a mapped array from a costumed post type. I created and saved the costum post type named 'myCpt' to which I linked it with acf type fields: (text and repeater) I was able to retrieve the text value but I can't get the repeater values.... Thanks for seeing the var_dump() image
Your help will be very valuable to me.
class myClass
{
function __construct()
{
var_dump($this->get_all());
}
function get_all()
{
$args = array(
'post_type' => 'myCpt',
'posts_per_page' => 999,
'post_status' => 'publish'
);
$myCpt = get_posts($args);
$myCpt_mapped = array_map(function ($myCpt) {
$id = $myCpt->ID;
return array(
'id' => $id,
'title' => get_field('maintitle', $id, false),
'subtitle' => get_field('subtitle', $id, false),
// 'services' => services repeater
'repField' => array(
'name' => get_sub_field('name', $id, false),
'img' => get_sub_field('img', $id, false)
)
);
}, $myCpt);
return array(
'myCpt' => $myCpt_mapped
);
}
}
global $myClass;
$myClass = new $myClass();}
resultat: var_dump()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
