Conditionaly require field based on another field in ACF WordPress

PHOTO EMBED

Thu Sep 08 2022 08:24:18 GMT+0000 (UTC)

Saved by @lancerunsite #wordpress #acf #require #field #conditionally #filter

<?php

add_filter( 'acf/validate_value/name=property_size', 'validate_property_size_field', 10, 4 );

function validate_property_size_field( $valid, $value, $field, $input ){

  // bail early if value is already invalid
  if ( ! $valid ) { return $valid; }

  $property_type = $_POST['acf']['field_5f0aa92348bb6'];

  if ( $property_type == 'Rent' ){
    if ( ! $value ) {
      $valid = __( 'This field is required for Rental Properties' );
    }
  }

  return $valid;

}
content_copyCOPY

https://itsmereal.com/advanced-custom-fields-conditional-required-field/