Support

Account

Home Forums Add-ons Options Page Can\'t translate options pages

Solved

Can\'t translate options pages

  • Hey guys!
    Translations doesn’t work with WPML & Polylang (with qtranslate-X all works fine) when I registered option page with custom post_id

    Here is my code:

    
                    $cpt_acf_page = array(
                        'page_title' => 'Projects Archive',
                        'menu_title' => 'Projects Archive',
                        'menu_slug' => 'projects-archive',
                        'capability' => 'edit_posts',
                        'position' => false,
                        'parent_slug' => 'edit.php?post_type=projects',
                        'icon_url' => false,
                        'redirect' => false,
                        'post_id' => 'cpt_projects',
                        'autoload' => false
                    );
    
                    acf_add_options_page( $cpt_acf_page );
    
  • Hi @tuskotrush

    Because you set the post_id, ACF tries to get the value from that exact ID in the wp_options table. As a workaround, you can use the ICL_LANGUAGE_CODE constant in the post_id option like this:

    'post_id' => 'cpt_projects_'.ICL_LANGUAGE_CODE,

    This will add extra suffix so the options ID will be like “cpt_projects_en” or “cpt_projects_fr”.

    To get the value from the options page, don’t forget to add the ICL_LANGUAGE_CODE constant like this:

    get_field('custom_field_name', 'cpt_projects_'.ICL_LANGUAGE_CODE);

    I hope this helps 🙂

  • So, I need to create two options pages?

  • Hey,

    I think the easier way is to do it like ACF does in the api_helpers.php File. Just add a filter like:

    add_filter('acf/validate_post_id', function( $post_id ){
    	if( $post_id === 'POST_ID' ){
    		$dl = acf_get_setting('default_language');
    		$cl = acf_get_setting('current_language');
    		
    		if( $cl && $cl !== $dl ) {
    			$post_id .= '_' . $cl;
    		}
    	}
    	return $post_id;
    });

    Where POST_ID is your options page post_id. This way you can just use the post_id in your theme and don’t have to add the ICL_LANGUAGE_CODE anywhere.

    I hope this helps.

  • Need Urgent Help Guys,

    I manage my organisation’s website through wordpress but at only beginner level in coding. I attempted to upgrade to latest version of ACF and lost almost all the content on the webpage plus graphics and all media.

    I tried to restore to the earlier version but run into a fatal error on lunching both the website and wordpress dashboard.

    This appears when i open the website and the wordpress dashboard.

    “Fatal error: Cannot redeclare class Acf_options_page in /home/wp-content/31/10414231/html/main/wp-content/plugins/advanced-custom-fields/core/admin/options_page.php on line 14”

    What did I do wrong? and is there a way to restore my content back to my website page?

  • Follow up,
    logged into ftp account – /home/wp-content/31/10414231/html/main/wp-content/plugins/advanced-custom-fields/core/admin/options_page.php on line 14”

    and on line 14 ({……) there’s nothing.

    *————————————————————————-*/

    class Acf_options_page
    {

    var $parent;
    var $dir;

    var $menu_name;
    var $menu_heading;

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.