jonathanp Posted July 1, 2014 Share Posted July 1, 2014 Hi Guys, I'm at a bit of a loss and wondered if some one can help me out. Basically I am trying to use the api to remove a specific repeater field. I have a template called userinfo which holds a repeater field called user_location. user_location repeater field holds a field called location_id. I am trying to find a specific repeater field by its id, and then delete it. However all attempts have resulted in fail, I am using the latest version of Processwire. I have made so many attempts it not really worth my putting any code below, but here was my last try. Many thanks Jonathan $deleteme = $data->geonameid; $thispage = wire('pages')->get("template=userinfo"); $locations = $thispage->find("user_location.location_geonameid=$deleteme"); $thispage->user_location->remove($locations); $page->save(); Link to comment Share on other sites More sharing options...
jonathanp Posted July 2, 2014 Author Share Posted July 2, 2014 Hi Guys, Just to note I solved this issue, see code below: $deleteme = $data->geonameid; $x = wire('pages')->get("template=userinfo,forkey=$thisuser"); foreach ($x->user_location as $value) { if ($value->location_geonameid == $deleteme) { $x->user_location->remove($value); $x->setOutputFormatting(false); $x->save(); } } I had to loop over each repeater then match the page based on custom id field, then remove. Seems slightly dirty but as the number of repeater fields should not exceed 10, should be sufficient enough. Many thanks 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