Support

Account

Home Forums Add-ons Repeater Field Remove sub_field?

Solved

Remove sub_field?

  • I’m syncing fields via a 3rd party data source and and wondering how I go about deleting sub_fields via code?

    I know there’s the update_sub_field function, can that be used to delete a row?

    I have a cron that runs daily and needs to delete rows based on a date.

    Should I just set it to a null value? I want to delete all the corresponding meta data correctly.

    Thanks!

  • Hi @aaronjheinen

    There’s actually a new API function release with ACF 5.2.7 called delete_sub_field() which you can use. It does however set it to null thus not completely deleting the entry.

    It takes the field key and the post ID (or user id or whatever).

    Try it out!

  • Since this was only setting it to null and not actually deleting the row I wanted a better solution. I came up with this which essentially gets the position of the field you want and moves every row after it back one and then removes the last row of the repeater thus completely deleting that value.
    https://gist.github.com/aaronjheinen/53ff4a44362927711d37

  • Hi @aaronjheinen your link is down! Can I see your solution? Thanks

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.