@hube2 There are some libraries to easily valid a phone number : https://github.com/giggsey/libphonenumber-for-php
But you’re right : outside US, the phone parts don’t make sense. Even in US, the parts work for a cell number ?
@webendev Apparently Gravity Forms valid only US format. The International option valids… nothing
Code snippet from the plugin :
$phone_formats = array(
'standard' => array(
'label' => '(###) ###-####',
'mask' => '(999) 999-9999',
'regex' => '/^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$/',
'instruction' => '(###) ###-####',
),
'international' => array(
'label' => __( 'International', 'gravityforms' ),
'mask' => false,
'regex' => false,
'instruction' => false,
),
);
$field['parent']
returns a group name (not a field). acf_get_field
works on it ? And event if it works, i will get the group in the good context in order to have its parent ? (A group can have a parent ?)
When i have time i will test but i have little hope.
Anyway, i will update this post with the result
Yes, for the moment i get the parent field from root group and i go through its children :
add_filter( 'acf/get_fields', 'acf_get_fields', 10, 2 );
function acf_get_fields( $fields, $parent ) {
if ( $parent['key'] === 'group1' ) {
foreach ( $fields as &$field ) {
if ( $field['name'] === 'my_parent_field' ) {
foreach ( $field['sub_fields'] as $k => &$sub_field ) {
if ( $sub_field['name'] === 'my_target_field' ) {
// my code
}
}
}
}
}
return $fields;
}
But it would be great if acf_get_field_ancestors works with clone fields 🙂
Sadly, i looked at the source code and apparently, it could takes a lot of work.
Hi,
I have found a solution to hide easily a field :
add_filter( 'acf/load_field/name=inscription_classe', [ $this, 'hide_field' ] );
public function hide_field( $field ) {
$field['conditional_logic'] = 1;
return $field;
}
The only problem is : if the field is manually posted with the form (by dom modification or http request modification), the field is saved to the db.
Not terrible because i don’t want form submitter can change this field. I tried readonly
disabled
no effect on db saving.
Always no solution to hide completely a field without the possibility to submit it ?
Perfect !
Thank you both 🙂
Hi @elliot, i use ACF PRO 5.4.6
OK thank you 🙂
Hi,
Thank you for your answer :).
I added menu_slug option :
acf_add_options_sub_page( array(
'page_title' => 'Génération',
'menu_title' => 'Génération',
'parent_slug' => 'edit.php?post_type=[post_type_slug],
'menu_slug' => 'generation',
) );
Same behavior : url wp-admin/edit.php?post_type=[post_type_slug]&page=generation
is redirected to wp-admin/admin.php?page=generation
(So menu is deactivated)
In fact, the redirect url is hard coded at the line 236 of file
advanced-custom-fields-pro/pro/admin/options-page.php
(ACF 5.4.6):
wp_redirect( admin_url("admin.php?page={$plugin_page}&message=1") );
Finally i used wpdb to execute this request:
SELECT
wp_posts.ID
FROM
wp_posts
INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
LEFT JOIN wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id AND mt1.meta_key = 'rc_cp_min_0')
LEFT JOIN wp_postmeta AS mt2 ON (wp_posts.ID = mt2.post_id AND mt2.meta_key = 'rc_cp_max_0')
LEFT JOIN wp_postmeta AS mt3 ON (wp_posts.ID = mt3.post_id AND mt3.meta_key = 'rc_cp_min_1')
LEFT JOIN wp_postmeta AS mt4 ON (wp_posts.ID = mt4.post_id AND mt4.meta_key = 'rc_cp_max_1')
LEFT JOIN wp_postmeta AS mt5 ON (wp_posts.ID = mt5.post_id AND mt5.meta_key = 'rc_cp_min_2')
LEFT JOIN wp_postmeta AS mt6 ON (wp_posts.ID = mt6.post_id AND mt6.meta_key = 'rc_cp_max_2')
WHERE
1 = 1
AND (wp_postmeta.meta_key = 'code pays'
AND wp_postmeta.meta_value = 'fr')
AND ((mt1.meta_value <= 7000 AND mt2.meta_value >= 7000)
OR (mt3.meta_value <= 7000 AND mt4.meta_value >= 7000)
OR (mt5.meta_value <= 7000 AND mt6.meta_value >= 7000))
AND wp_posts.post_type = 'distributeur'
AND wp_posts.post_status = 'publish'
LIMIT 0 , 1
Duration: 0.031 sec
It’s exactly the same code except that meta_key conditions are on join and not on where and i replaced INNER JOIN by LEFT JOIN.
My knowledge of Mysql optimization is limited so i don’t know exactly why it’s really faster but it works 🙂
If the query does not differentiate between fields in different rows, i don’t understand why there is a repeater field. One field stat_date and one field end_field are enough ^^’.
Finally, WP_Query is too slow : 17 seconds with 2 rows and timeout with 3 rows and i don’t know why, the request does not seem so complicated :
Array
(
[post_type] => distributeur
[posts_per_page] => 1
[meta_query] => Array
(
[relation] => AND
[0] => Array
(
[key] => code pays
[value] => fr
)
[1] => Array
(
[relation] => OR
[0] => Array
(
[relation] => AND
[0] => Array
(
[key] => rc_cp_min_0
[value] => 7000
[type] => numeric
[compare] => <=
)
[1] => Array
(
[key] => rc_cp_max_0
[value] => 7000
[type] => numeric
[compare] => >=
)
)
[1] => Array
(
[relation] => AND
[0] => Array
(
[key] => rc_cp_min_1
[value] => 7000
[type] => numeric
[compare] => <=
)
[1] => Array
(
[key] => rc_cp_max_1
[value] => 7000
[type] => numeric
[compare] => >=
)
)
[2] => Array
(
[relation] => AND
[0] => Array
(
[key] => rc_cp_min_2
[value] => 7000
[type] => numeric
[compare] => <=
)
[1] => Array
(
[key] => rc_cp_max_2
[value] => 7000
[type] => numeric
[compare] => >=
)
)
)
)
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[comments_popup] =>
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[fields] =>
[menu_order] =>
[...]
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[update_post_meta_cache] => 1
[nopaging] =>
[comments_per_page] => 50
[no_found_rows] =>
[order] => DESC
)
SQL :
SELECT SQL_CALC_FOUND_ROWS
wp_posts.ID
FROM
wp_posts
INNER JOIN
wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
INNER JOIN
wp_postmeta AS mt1 ON (wp_posts.ID = mt1.post_id)
INNER JOIN
wp_postmeta AS mt2 ON (wp_posts.ID = mt2.post_id)
INNER JOIN
wp_postmeta AS mt3 ON (wp_posts.ID = mt3.post_id)
INNER JOIN
wp_postmeta AS mt4 ON (wp_posts.ID = mt4.post_id)
INNER JOIN
wp_postmeta AS mt5 ON (wp_posts.ID = mt5.post_id)
INNER JOIN
wp_postmeta AS mt6 ON (wp_posts.ID = mt6.post_id)
WHERE
1 = 1
AND ((wp_postmeta.meta_key = 'code pays'
AND CAST(wp_postmeta.meta_value AS CHAR) = 'fr')
AND (((mt1.meta_key = 'rc_cp_min_0'
AND CAST(mt1.meta_value AS SIGNED) <= '7000')
AND (mt2.meta_key = 'rc_cp_max_0'
AND CAST(mt2.meta_value AS SIGNED) >= '7000'))
OR ((mt3.meta_key = 'rc_cp_min_1'
AND CAST(mt3.meta_value AS SIGNED) <= '7000')
AND (mt4.meta_key = 'rc_cp_max_1'
AND CAST(mt4.meta_value AS SIGNED) >= '7000'))
OR ((mt5.meta_key = 'rc_cp_min_2'
AND CAST(mt5.meta_value AS SIGNED) <= '7000')
AND (mt6.meta_key = 'rc_cp_max_2'
AND CAST(mt6.meta_value AS SIGNED) >= '7000'))))
AND wp_posts.post_type = 'distributeur'
AND (wp_posts.post_status = 'publish'
OR wp_posts.post_status = 'acf-disabled'
OR wp_posts.post_status = 'future'
OR wp_posts.post_status = 'draft'
OR wp_posts.post_status = 'pending')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0 , 1
Yes it’s a little more complicated than ACF example and they are postal codes and not dates but principle is the same.
That’s what i thought :/
But you confirm there is a mistake in documentation ? How we can report the error ?
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.