@hube2 That works.
Also I think I actually fixed the issue by correcting a typo that isn’t included in my code sample above. So this can be closed as “solved”.
But I am still curious: do you know why update_field() would return an int instead of bool?
@hube2 That’s good to know. I actually ended up arriving at that solution a while ago, so I am using field keys, but the issue keeps happening.
I don’t think I can edit my original post anymore, but the ACF_Module
class has those field keys stored as parameters (so I don’t have to keep changing it everywhere). So near the end of my PHP code, $module->documents_field
is the same as field_6255b86755ad6
.
Here is an example set of data for $documents_field
:
$documents_field = [
[ 'document_id' => 2241, 'module_id' => 201, 'order' => 1.0 ],
[ 'document_id' => 2242, 'module_id' => 201, 'order' => 2.0 ],
[ 'document_id' => 2243, 'module_id' => 201, 'order' => 3.0 ],
];
$documents_field_deleted = delete_field('field_6255b86755ad6', 201);
$documents_field_updated = update_field('field_6255b86755ad6', $documents_field, 201);
I’m even making sure that each int is an int or float by using the intval()
and floatval()
functions. But for some reason, this isn’t working.
Not sure if this helps, but here’s the declaration and constructor for my ACF_Module
class:
// ACF_Post is another custom class that just contains the same parameters as the WP_Post object, which isn't extendable
class ACF_Module extends ACF_Post
{
public $documents = [];
public $post_type = 'acf_module';
public $documents_field = 'field_6255b86755ad6';
public function __construct($post_id, $attr = [], $module_id = -1)
{
$post_id = intval($post_id);
parent::__construct($post_id, $attr);
$this->documents = !empty(get_field($this->documents_field, $post_id)) ? get_field($this->documents_field, $post_id) : false;
}
// [...]
}
But the question is when can you check? In my above example, I am checking during acf/pre_save_block
, but at that point, the anchor
attribute is already overwritten. I need to be able to hook into the function that is overwriting the attribute, but I can’t seem to find a filter that lets me do that.
I need them to always be the same so that I can create a predictable hyperlink to it. The current problem is that it keeps getting regenerated every time I save the post.
I was actually able to get this working by duplicating the Field Group and deleting the old one.
I had the same problem. I started this thread only a few days before yours.
I was actually able to get this working by duplicating the Field Group and deleting the old one. Since the fields had the same names, they were still populated with all of the old data.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.