Support

Account

Home Forums General Issues Disable Options for Select Field Reply To: Disable Options for Select Field

  • The problem is we also have an “edit” possibility for not logined users by some “hidden key value” which they receive through email.

    The post_id is then selected and given to the acf_form object

    
     acf_form(array(
         'id' => 'acf-form',
         /* (int|string) The post ID to load data from and save data to. Defaults to the current post ID.
                Can also be set to 'new_post' to create a new post on submit */
         'post_id' => $post_id,
    ...
    

    Sadly in the called filters function for select field the value is always “null” even When the priority is set to 1 / 10 / 20 / 1000.

    A quick look into the source code even shows me that even in the filter ‘acf/pre_render_fields’ the values aren’t set….

    from acf_field_functions.php

    
    /**
     * acf_render_fields
     *
     * Renders an array of fields. Also loads the field's value.
     *
     * @date	8/10/13
     * @since	5.0.0
     * @since	5.6.9 Changed parameter order.
     *
     * @param	array $fields An array of fields.
     * @param	(int|string) $post_id The post ID to load values from.
     * @param	string $element The wrapping element type.
     * @param	string $instruction The instruction render position (label|field).
     * @return	void
     */
    function acf_render_fields( $fields, $post_id = 0, $el = 'div', $instruction = 'label' ) {
    
    	// Parameter order changed in ACF 5.6.9.
    	if( is_array($post_id) ) {
    		$args = func_get_args();
    		$fields = $args[1];
    		$post_id = $args[0];
    	}
    
    	/**
    	 * Filters the $fields array before they are rendered.
    	 *
    	 * @date	12/02/2014
    	 * @since	5.0.0
    	 *
    	 * @param	array $fields An array of fields.
    	 * @param	(int|string) $post_id The post ID to load values from.
    	 */
    	$fields = apply_filters( 'acf/pre_render_fields', $fields, $post_id );
    
    	
    	// Filter our false results.
    	$fields = array_filter( $fields );
    
    	// Loop over and render fields.
    	if( $fields ) {
    		foreach( $fields as $field ) {
    
    			// Load value if not already loaded.
    			if( $field['value'] === null ) {
    				$field['value'] = acf_get_value( $post_id, $field );
    			}
    
    			// Render wrap.
    			acf_render_field_wrap( $field, $el, $instruction );
    		}
    	}
    
    	/**
    	*  Fires after fields have been rendered.
    	*
    	*  @date	12/02/2014
    	*  @since	5.0.0
    	*
    	* @param	array $fields An array of fields.
    	* @param	(int|string) $post_id The post ID to load values from.
    	*/
    	do_action( 'acf/render_fields', $fields, $post_id );
    }
    

    the filter add_filter('acf/load_field/name=myselect'.. is called by far before the actual render of the select field and sadly also way before the value is set.
    So your code doesn’t work.