Sorry, wrong answer, I read too fast
I’m sorry, I realise i’m reviving an old topic but it seems quite important, and i’m a bit confused now : since wp_kses_post is now used by default on $_POST, i’m not sure what is the point of what @sododesign suggests (on December 8 2015) ?
What am i missing here ? Does it mean the default wp_kses_post doesnt deal with repeater fields correctly ?
Do we still need to worry about ACF front-end forms input sanitization or is it fully and reliably taken care of with thanks to the kses parameter ?
Ok, found a solution using
https://support.advancedcustomfields.com/forums/topic/wp_query-using-meta_query-for-an-acf-checkbox-field/
The following works :
[meta_query] => Array
(
[relation] => OR
[0] => Array
(
[key] => ciblages_ciblage_secteur
[value] => 373
[compare] => LIKE
)
[1] => Array
(
[key] => ciblages_ciblage_secteur
[value] => 374
[compare] => LIKE
)
)
)
Hello again, I tried solving this by myself, but no luck so far.
For context :
– “Cities” is a repeater field. Each row is a “city” (a city where you stop while on a road trip).
– For each row (city), I ask for start_date and end_date (arrival & departure); these fields (respectively field_5d720d97435c3 and field_5d720db1435c4 are inside a group field field_5d720d70435c2)
I’d like to make sure, for each row INDEPENDANTLY that start_date < end_date
So far, as soon as a row is not valid, error appears for each row, even if its valid.
I have no idea to validate each row independantly.
Here’s my code :
function hotel_form_validate_voyage_form( $valid, $value, $field, $input )
{
// bail early if value is already invalid
if( !$valid ) { return $valid; }
$cities= $_POST['acf']['field_5d6fb2c56a359'];
foreach($citiesas $city)
{
$start_date= $city['field_5d720d70435c2']['field_5d720d97435c3'];
$end_date= $city['field_5d720d70435c2']['field_5d720db1435c4'];
$start_date_timestamp= turn_acf_date_into_timestamp($start_date);
$end_date_timestamp= turn_acf_date_into_timestamp($end_date);
if($end_date_timestamp<= $start_date_timestamp)
{
$valid = "ERROR";
}
}
return $valid;
}
add_filter('acf/validate_value/key=field_5d720d97435c3', 'hotel_form_validate_voyage_form', 10, 4);
add_filter('acf/validate_value/key=field_5d720db1435c4', 'hotel_form_validate_voyage_form', 10, 4);
(function turn_acf_date_into_timestamp is defined elsewhere and works fine)
I’d greatly appreciate help here 🙂
That did the trick, thank you !
Hmm, the filter mentionned above doesn’t seem to work for me.
I’m using a parent+child template : placed it in parent then child’s function.php, then both, to no avail. As soon as I deactivate ACF Pro, the metabox (Custom Fields) is back.
Am I the only one ?
I’m using ACF 5, and I added the missing }
🙂
I’m adding the function in a plugin file : I want to be able to add an options sub page to a CPT menu, and so far, I’m able to create and register the page, but ACF won’t detect it in the location rules.
Hi,
whether I use my code or yours, the location rule tells me “no options page created” : “emplacements de diffusion” is never detected.
That’s where i’m stuck :/
Also, are you sure I should be using acf_add_options_page instead of acf_add_options_sub_page ?
! Found the solution : I should have used post_tag instead of tag.
That’s not very intuitive, but glad I stumbled upon a reference in the Codex.
Eliott, I suggest you add this in the get_field documentation, it’s rather clear for category_ID, but not for tags, and I can’t be the only one trying to do that 🙂
Cheers,
Baptiste
Alright, nevermind, I found a solution, thanks to this topic :
http://support.advancedcustomfields.com/forums/topic/adding-fields-using-functions-php/
=> In ACF menu, there is an export feature I had never noticed. (my bad).
I used it to get PHP code for my fields group (options page), pasted it into functions.php and VOILA : it works as expected.
Only tiny bug I noticed is it doesn’t handle accentuated characters
Sorry for the noob question.
… and glad to see once again how great ACF is !
Cheers,
Baptiste
(don’t know what’s the best way to distribute your plugin, but I can assure you a lot of people would find it interesting)
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.