Guy Verville Posted August 5, 2018 Share Posted August 5, 2018 Hi, I must change via API a field called member_mx_images that includes an image and a page reference field called crm_products_sold. I have tried a lot of things but to no avail. I based my code along: https://processwire.com/api/fieldtypes/repeaters/ The code below shows $changed which is the repeated I must change. $products is an array of page IDs. $changed = $p->member_mx_images->eq(array_key_exists($responseChanged['basename'],$indexMxArray)); $products = explode(',',$responseChanged['products']); $changed->crm_products_sold = $products; $p->of(false); $changed->of(false); $changed->save(); $p->save(); Link to comment Share on other sites More sharing options...
Guy Verville Posted August 5, 2018 Author Share Posted August 5, 2018 It's a false alert. I was compare the page field to itself. However, to be able to update a page reference, you have to set it to null before. If not, the pages are added. $changed = $p->member_mx_images->eq(array_key_exists($responseChanged['basename'], $indexMxArray)); $changed->of(false); $products = explode(',', $responseChanged['products']); $changed->crm_products_sold = null; $changed->crm_products_sold = $products; $changed->save(); And we do not need to save the page where the mx_field belongs to, because the variable $changed is in itself a page. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now