Support

Account

Home Forums Backend Issues (wp-admin) Dropdown value saved but not loaded back Reply To: Dropdown value saved but not loaded back

  • Hi James,

    Thanks again for you time.
    There is obviously informations missing on my side, so please allows me to provide some details:

    All of the following is for the admin backend only
    • I’m editing an article, on which is attached a flexible content field.
    • This flexible content, contains (among others) a gallery group of fields (I’m using the “clone” field type into my flexible content field for that).
    • This gallery group of fields contains (among others), a repeater field named “image_size”
    • This “image_size” repeater contains the select (image_reference) I want to hook and populate with the database value.

    Here’s a draw:

    ┌─────────────────────────────────────────────────────────────────────┐
    │Fields Group (Flexible Content)                                      │
    │                                                                     │
    │  ┌---------------------------------------------------------------┐  │
    │  │                      Some Fields Groups                       │  │
    │  └---------------------------------------------------------------┘  │
    │  ┌───────────────────────────────────────────────────────────────┐  │
    │  │Gallery Fields Group                                           │  │
    │  │                                                               │  │
    │  │ ┌-----------------------------------------------------------┐ │  │
    │  │ │                        Some Fields                        │ │  │
    │  │ └-----------------------------------------------------------┘ │  │
    │  │ ┌───────────────────────────────────────────────────────────┐ │  │
    │  │ │Image Size Field (Repeater)                                │ │  │
    │  │ │                                                           │ │  │
    │  │ │                      ┌─────────────┐       ┌─────────┐    │ │  │
    │  │ │     Image reference: │           ▼ │  Size:│         │    │ │  │
    │  │ │                      └─────────────┘       └─────────┘    │ │  │
    │  │ │                      ┌─────────────┐       ┌─────────┐    │ │  │
    │  │ │     Image reference: │           ▼ │  Size:│         │    │ │  │
    │  │ │                      └─────────────┘       └─────────┘    │ │  │
    │  │ │                      ┌─────────────┐       ┌─────────┐    │ │  │
    │  │ │     Image reference: │           ▼ │  Size:│         │    │ │  │
    │  │ │                      └─────────────┘       └─────────┘    │ │  │
    │  │ └───────────────────────────────────────────────────────────┘ │  │
    │  │                                                               │  │
    │  └───────────────────────────────────────────────────────────────┘  │
    │                                                                     │
    └─────────────────────────────────────────────────────────────────────┘

    So far, my code (ultra basic, still not working) is the following:

    if (is_admin()){
    	$fieldKey = 'field_5831de130046f';
    
    	function my_acf_load_field($field){
    		global $post;
    		$db_value = get_field('image_size', $post->ID, false);
    		return $field;
    	}
    	add_filter('acf/load_field/key=' . $fieldKey, 'my_acf_load_field', 10, 1);
    }

    First question: If I want to hook the ‘image_reference’ select, the $fieldKey should be the ‘image_reference’ key right?

    Second question: what should be the field I’m asking for with get_field? If my hook (add_filter) is set on ‘image_reference’, I should have get_field(‘image_reference’)?

    I’ve to admit I’m completely lost here…
    Depending the get_field I’m doing (with nothing more than this action), even the “return $field” doesn’t work anymore.

    I tried to contact you in private, but looks like it’s not possible.
    If you want, you can try contacting me on iMessage (same nickname [at] mac.com) or Skype (same nickname).

    Best regards.