我使用来自插件Formidable Pro(frm_to_email
)的钩子,我绝对需要拥有当前页面的ID(对于高级自定义字段)。由于代码位于function.php
,我似乎无法检索它。我能做些什么来获得这个价值?获取钩子的当前页面ID
function custom_set_email_value($recipients, $values, $form_id, $args){
global $post;
$profil_obj = get_field('profil_obj', $post->ID); // If I put the ID directly (10 for example), it works
if($form_id == get_field('popup_form_id', 'option') && $args['email_key'] == get_field('popup_email_id', 'option')){
if($profil_obj) {
foreach($profil_obj as $post) {
setup_postdata($post);
$recipients[] = get_field('profil_email', $post->ID);
}
}
wp_reset_postdata();
}
return $recipients;
}
add_filter('frm_to_email', 'custom_set_email_value', 10, 4);
这很好用!谢谢! – meneldil