Support

Account

Forum Replies Created

  • Hi James @acf-support

    ok, this plugin logic makes sense 🙂

    Nice to know that, thanks for your help

  • @hube2 Thank you very much for your patience. 🙂

  • @hube2 thanks for helping:

    I have find a way to solve it:

    First I set the fields as globals with there default values in function.php.

    
    function acf_global_vars() {
    
        global $white_menu;
        $white_menu = get_field('top_nav_color', 'option'); 
    	if ($white_menu === NULL) { $white_menu = '1'; } // default value
    	
    	// ------ //
    	
    	global $image_white;
        $image_white = get_field('logo_white', 'option');
    	if ($image_white === NULL) { 
    		$image_white['url'] = get_template_directory_uri() . '/img/small-business-logo-white.svg'; 
    		$image_white['alt'] = 'hallo'; 
    	} // default value
    	
    	// ------ //
    	
    	global $image_normal;
        $image_normal = get_field('logo_normal', 'option'); 
    	if ($image_normal === NULL) { 
    		$image_normal['url'] = get_template_directory_uri() . '/img/small-business-logo.svg';
    		$image_normal['alt'] = 'hallo'; 
    	} // default value
    	
    	// ------ //
    	
    	global $logo_white_width;
        $logo_white_width = get_field('logo_white_width', 'option'); 
    	if ($logo_white_width === NULL) { $logo_white_width = '200'; } // default value
    	
    	// ------ //
    	
    	global $logo_normal_width;
        $logo_normal_width = get_field('logo_normal_width', 'option'); 
    	if ($logo_normal_width === NULL) { $logo_normal_width = '200'; } // default value
    	
    	// ------ //
    	
    	global $top_search;
        $top_search = get_field('top_search_show', 'option');
    	if ($top_search === NULL) { $top_search = '1'; } // default value
    
    }
    
    add_action( 'template_redirect', 'acf_global_vars' );
    

    Than I call the globals in the template header.php

    global $white_menu, $image_white, $image_normal, $logo_white_width, $logo_normal_width, $top_search;

    And start the IF

    <?php if( $white_menu ): ?>
    <img class="logo-white" src="<?php echo $image_white['url']; ?>" alt="<?php echo $image_white['alt']; ?>" width="<?php echo $logo_white_width; ?>" />
    <?php endif; ?> 

    Is this the best method I can have?

  • @acf-support I’m a web designer and not a developer, but I would like to learn some things for myself. I’m happy that there is this acf plugin. It gives me more freedom in the template development. It’s amazing 🙂

    In most cases, few PHP skills are sufficient. Sorry for my question.

    But, I can’t unterstand, why the automatically export is no main feature? The PHP export is the best way to get all of the fields to the different theme users. With the JSON export, each user must be sync the new fields manually. With a theme update, which include the new fields in the exported php file is the better way for me. Because then the user has all new fields, without doing something.

    That’s the reason, because I want create a automatically generated file export. It is less error-prone, if you should forget to update the file. Or is there a better way?

    My english is not the best, I hope you can understand me 🙂

  • Ok I tested your first solution:

    $white_menu = get_field('top_nav_color', 'option');
    	if ($white_menu === NULL) {
    	  $white_menu = '1';
    	}

    This is my example and it works, by including this in the specific template, where the field is called.

    But, now I can’t unterstand your next solution. Is this a workaround for all true/false fields or do I have to define it for each field also?

    The easier way is to write a documentation, with explaining to go to the backend and click the update button 🙂

  • I tried it but I do not know if that is correct.

    function mytest() {
    	$value = get_field('my_options', 'option');
    	if ($value === NULL) {
    	  $value = '1';
    	}
    }
    
    add_filter( 'acf/load_field/key=field_580b7d8b9ceea', 'mytest' );

    $value = ‘1’ = true (from True/False field)?!

    Unfortunately it does not work.

  • @hube2 thanks for your reply. With both methods, then I would have to do this for each field? This is very complex with over 50 fields. 🙁

    Is there a way to make a virtual click by the option page update button? 🙂 Can I use a acf function for this?

    I can not understand this exactly.

    $value = get_field('my_options', 'option');

    Is one of my option fields with a default value.

    $value = 'my-default-value';

    But what is ‘my-default-value’ or the content of this? The value comes from the field. And I look for this directly after the theme setup.

  • @acf-support is there a way to trigger the option page update via theme setup?

  • @acf-support

    Thanks for your help. My PHP knowledge is not enough, for creating this . 🙂
    I can copy the code, but I don’t know, how I create the automatically file export with all selected field to my theme folder. 🙁

  • Any idea for automatically generated php file by editing and saving from ACF admin?

  • Ok, I find a solution. I can export manually the field group to php and load these in the function.php.

    Than I set the textdomain:

    
    function custom_acf_settings_textdomain($domain) {
      	return 'textdomain';
    }
    
    add_filter('acf/settings/l10n_textdomain', 'custom_acf_settings_textdomain');
    
    

    And all labels be found by Poedit template import. Thats fine 🙂

    Is there a way to generate the php field group export automatically, by edit and saving the fields in ACF admin?

  • I have the generated .JSON files at my theme in the folder “acf-json”, with all my own field labels.

    But how I can change the output from label value to a textdomain value?

Viewing 12 posts - 51 through 62 (of 62 total)