Conversation
supportHello! I could not use the uniqueness for a Relation field! Is this possible and how can i achieve it? https://wordpress.org/plugins/validated-field-for-acf/
Hi @leonardo_ndo , Is it not working for any of the unique settings or one in particular? Can you let me know what version of ACF, Validated Field, and WordPress you are using? Thanks!
Hello, thanks for the quick answer. I’ve tried all the unique options, none of them works. It shows me the error, even if there is no posts inserted. Versions ACF: 4.4.3 VF: 1.7.7 WP: 4.3.1 Thanks in advance
Unfortunately this isn’t working correctly in the current version of the plugin, but I am working on version 2.0 that will handle this much differently. The issue is that the relationship field values are stored as an array of post IDs which is then serialized before it’s saved to the postmeta table. To make things trickier, you can resort the selected values if more than one is allowed which resulted in some funky LIKE statements to try and detect dupes. The new version will hook into the field update and save the individual IDs to their own meta keys, along with a sorted array which we can rely on to determine uniqueness. Couple that with repeater fields and the new support for User and Option meta fields, and the code that generates the SQL statements has gotten a little crazy. Nearly 500 lines :/ The latest code can be found here https://github.com/doublesharp/validated-field-for-acf , but note that it is still a little buggy (and I haven’t checked in the new relationship code, should have that in a few hours).
I’ll wait for a stable version then. Thank you very much
Hi @leonardo_ndo , Is it not working for any of the unique settings or one in particular? Can you let me know what version of ACF, Validated Field, and WordPress you are using? Thanks!
Hello, thanks for the quick answer. I’ve tried all the unique options, none of them works. It shows me the error, even if there is no posts inserted. Versions ACF: 4.4.3 VF: 1.7.7 WP: 4.3.1 Thanks in advance
Unfortunately this isn’t working correctly in the current version of the plugin, but I am working on version 2.0 that will handle this much differently. The issue is that the relationship field values are stored as an array of post IDs which is then serialized before it’s saved to the postmeta table. To make things trickier, you can resort the selected values if more than one is allowed which resulted in some funky LIKE statements to try and detect dupes. The new version will hook into the field update and save the individual IDs to their own meta keys, along with a sorted array which we can rely on to determine uniqueness. Couple that with repeater fields and the new support for User and Option meta fields, and the code that generates the SQL statements has gotten a little crazy. Nearly 500 lines :/ The latest code can be found here https://github.com/doublesharp/validated-field-for-acf , but note that it is still a little buggy (and I haven’t checked in the new relationship code, should have that in a few hours).
I’ll wait for a stable version then. Thank you very much