Home › Forums › Add-ons › Options Page › WPML and ACF Options › Reply To: WPML and ACF Options
@flashpunk: here is how i did it:
1) Created a custom post type, named
my_settings. Obviously, is translatable by WPML
2) Created a page template for each settings page. Fortunate, i had only two pages. So, now we have
3) Created a page for each template. For now it’s enough to have them in base language (english)
4) Created an option page that sets the id’s for these pages. (there is a post object or something like this; you need the ID) (for the sake of simplicity, i named all options here as
wpml_*). We need this only for base language.
5) The old option pages (those with real … options) are now set as to be displayed on certain templates (those that we set earlier)
Done with admin!
Right now, we need a way to get the id for
get_field('our_awesome_setting', ID) function.
We first get the ID for base language page:
$home_carousel = get_field( 'wpml_options_home_carousel_page', 'option' );
We then get the translated page (or base page if there is no translation):
$home_carousel_id = icl_object_id( $home_carousel->ID, 'my_settings', true, ICL_LANGUAGE_CODE );
Then we set a constant with this translated ID:
define( 'MY_OPTIONS_HOME_CAROUSEL', $home_carousel_id );
After this, everything is just fine. We can get fields as usual, but instead of using
option param, you use this constant we defined earlier:
$gallery_rows = get_field( 'home_gallery_rows', MY_OPTIONS_HOME_CAROUSEL );
(let me know if i explained well)
Very, very late edit: you can set templates to custom post types by using this plugin: http://wordpress.org/plugins/custom-post-type-page-template/
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
CPT registration is coming to ACF! We demoed the new feature during the most recent session of ACF Chat Fridays. Check out the summary for the details. https://t.co/k2KQ3WWBAz— Advanced Custom Fields (@wp_acf) March 7, 2023
© 2023 Advanced Custom Fields.