Home › Forums › General Issues › Delete_row() selector not working
Hi guys!
When i use the function delete_row() en have a parameter selector it ignores it and always deletes the last row. I use repeater field btw.
My code looks like this.
delete_row(‘post_comments’, ‘1’, $post_id);
and it results in always deleting the last row and never the first or second when i change the number.
try using an integer instead of a string for the row
delete_row('post_comments', 1, $post_id);
This stil didn’t solve the issue. When i try use 1 or 2 as parameter it stil always deletes the last row.
I’m using ACF PRO 5.3.3.2 btw. I have the feeling this is more like a bug?
Yes, there is a bug, line 1813 of /api/api-template.php
if( $row = count($rows) ) {
should be
if( $row == count($rows) ) {
I reported it and the developer fixed it and it will be in the next update.
I fixed the bug. Is it true that delete_row() only clears all fields and not removing the entire row?
I honestly don’t know what delete_row actually does, I’ve never used it, haven’t had a reason to yet. According to the documentation it deletes the entire row and is not supposed to just clear the values from it. So if the repeater has 5 rows and you delete on of them then it should only have 4 rows, at least that’s what I get from reading this http://www.advancedcustomfields.com/resources/delete_row/
It only deletes the row when it is the last row.
But when i want to delete the second row and not the first or the third it just clears the second row.
I tried checking into this, looking at the ACF code to see what it’s doing, but couldn’t really follow it. If it’s working the way you say it is then it might be a bug. You might want to contact [email protected] and report it.
I made a workaround with an true or not true field so that it looks like the row is deleted.
From a developers perspective i can understand why the function doesn’t work so i don’t think it’s a bug or something. It’s just hard to change all the row fields by one function. When you use acf_form() it’s easy to delete because the other fields get saved to.
The topic ‘Delete_row() selector not working’ is closed to new replies.
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.