Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter jimi111

    (@jimi111)

    Thanks a lot for the code! For me it would take probably a few hours to write this.
    And especially for reducing database bloating with useless values
    // Return null to not save the value as a meta

    In case someone with very low programming skills like me need it for the post status.

    /*
     * Field: My Post Status - Load Value
     */
    add_filter('acf/load_value/name=post_status', 'acf_post_status_load', 10, 3);
    function acf_post_status_load($value, $post_id, $field){
    
        // Bail early if not in a Post
        if(!is_numeric($post_id))
            return $value;
        
        // Retrieve Current Post Status
        $post_status = get_post_status($post_id);
        
        // Force the Field value to load the Current Post Status
        $value = $post_status;
    
        // Return
        return $value;
    
    }
    
    /*
     * Field: My Post Status - Save Value
     */
    add_filter('acf/update_value/name=post_status', 'my_acf_post_status_save', 10, 3);
    function my_acf_post_status_save($value, $post_id, $field){
        
        // Bail early if not in a Post
        if(!is_numeric($post_id))
            return $value;
        
        // Update Current Post to the selected Post Status
        wp_update_post(array(
            'ID'        => $post_id,
            'post_status' => $value,
        ));
        
        // Return null to not save the value as a meta
        return null;
    
    }
    Thread Starter jimi111

    (@jimi111)

    Thanks for the fast reply! Now I see, so at a current state they are just a value loaders for developers.
    >I added the feature request to the Trello Board to let users automatically update the current post
    Would be great!

    Thread Starter jimi111

    (@jimi111)

    Hello
    I just tested and it works like a charm! You are really really cool, man! Thanks a lot!

    Thread Starter jimi111

    (@jimi111)

    I’m afraid it still broken.

    This is how it normally works with manual export:
    Add thise code to functions.php

    add_action('acf/init', 'acf_settings');
    function acf_settings() {
        acf_update_setting('l10n', true);
        acf_update_setting('l10n_textdomain', 'theme');
    }

    Go to ACF – Tools – Export Field Groups – Generate PHP
    Result: Every string is wrapped in __()
    ie. ‘label’ => __(‘Custom Label’, ‘theme’)

    Now with Extended auto sync:
    Edit Field Group – Auto Sync – Php – checked
    Press Update
    Result: if you look inside generated file in /theme/acfe-php/group_ID.php nothing is wrapped

    Also, if you go to ACFE Settings page, l10n Textdomain is boolean, and it should contain value ‘theme’ – acf_update_setting(‘l10n_textdomain’, ‘theme’);

    Thread Starter jimi111

    (@jimi111)

    Thanks a lot, Konrad!

Viewing 5 replies - 1 through 5 (of 5 total)