【问题标题】:acf/validate_value, error sent to an other windows than acf_form's oneacf/validate_value,发送到 acf_form 以外的其他窗口的错误
【发布时间】:2023-02-03 13:35:16
【问题描述】:

ACF 6.0.7、PHP 7.4.26、Apache 2.4.51

我创建了自定义帖子类型 entreprise 和 employee。

当我为企业创建员工时,我会搜索该员工是否不存在。我这样做:

add_filter('acf/validate_value/name=nomprenoms', 'existenceEmploye',10,4);

function existenceEmploye( $valid, $value, $field, $input_name ) {


$entreprise=$_GET['ent'];

  if ( !$value) {
      return __( "employee name is mandatory" );  
  }


$nomPrenoms=explode(",",$value);

if (strlen($nomPrenoms[0]) ==0 || 
    strlen($nomPrenoms[0]) == strlen($value) ||
    strlen($nomPrenoms[0]) == strlen($value) -1 ) {
  return __( "La syntaxe est nom, prenoms" ); 
}


$args = array(
'posts_per_page'    => -1,
'post_type'         => 'employe',
'meta_query'      => array (
  'relation'      =>'AND',
  array (
    'key'         =>'nomprenoms',
    'value'       =>$value,
    'compare'     =>'=',
     ),
array (
    'key'         =>'entreprise',
    'value'       =>$entreprise,
    'compare'     =>'=',
     ),
  ),

);

// var_dump($args);

$the_query = new WP_Query( $args );


if (count($the_query->posts)) {  
        wp_reset_postdata(); 
        return ( "The employee exits already" );  
    }
else {
          wp_reset_postdata(); 
}


  return $valid;
    
}


我预计错误消息会出现在 ACF 字段上方。事实上,ACF 字段消失了。 窗口是: error message 我有内部服务器错误 500

如果名称不存在或格式不正确,则错误消息将显示在 ACF 字段上方。 感谢您的帮助

【问题讨论】:

  • 将这段代码放在 config.php 文件中=> ini_set('display_errors','Off'); ini_set('error_reporting', E_ALL );定义('WP_DEBUG',真);定义('WP_DEBUG_DISPLAY',真);定义('WP_DEBUG_LOG',真);并检查 wp-content 文件夹调试文件,你可以找到确切的问题所在!
  • 非常感谢,我看到了我的错误,$_GET['ent'] 没有返回任何内容,而 'ent' 在 Url 中。我找到“entreprise”是因为我把它放在 ACF_Field 中并且我使用了 $entreprise=$_POST['acf'] ['field_63b7f8f0e992c'];

标签: wordpress advanced-custom-fields


【解决方案1】:

将这段代码放在 config.php 文件中=> ini_set('display_errors','Off'); ini_set('error_reporting', E_ALL );定义('WP_DEBUG',真);定义('WP_DEBUG_DISPLAY',真);定义('WP_DEBUG_LOG',真);并检查 wp-content 文件夹调试文件,你可以找到确切的问题所在!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-17
    相关资源
    最近更新 更多