0

I use a custom made plugin to load a custom post type.

And i use acf plugin to add custom fields to that post type.

Also, i use the acf plugin to add a theme options page with that code in my functions.php:

if( function_exists('acf_add_options_page') ) {

    acf_add_options_sub_page(array(
        'page_title'    => 'Theme Options',
        'menu_title'    => 'Theme Options',
        'parent_slug'   => 'options-general.php',
        'menu_slug'     => 'theme-general-settings',
        'capability'    => 'edit_posts',
        'redirect'      => false
    ));

}

I'm trying to use some custom fields from this theme options page to set up the post type labels. so in my post type plugin it looks like that:

function custom_post_type_pros() {

    $name_male = get_field('pros_single_name_male', 'option');
    $name_males = get_field('pros_single_name_males', 'option');

    $labels = array(
        'name'                => $name_males,
        'singular_name'       => $name_male,
        'menu_name'           => $name_males,

...

It worked. i entered some names in the options page and it did used them for the post type labels.

The problem is: After trying to change those options again it doesn't change the post type labels again. it sticks with the first option i entered.

What i have tried:

  1. So i thought maybe i need to make sure the post type plugin loads only after the options page, but i tried puting the code i metioned above in the head of my post type plugin instead of the functions.php, but it didn't work.

  2. Also tried turning the post type plugin off and on and it still uses that old option labels.

  3. Also tried changing the labels to static ones and the to those variables again. still the same old option is showing as the label. just don't know where does it come from...

I need some way to make those labels refresh and get the new names from the options page. every time the plugin loads or something...

Any suggestions?

Thanks.

  • What action does custom_post_type_pros run on? Note that variables within translation functions aren't translatable. You could have a default translatable value that is overridden by your option, but arguments in translation functions have to be static strings. – Milo Jan 3 '16 at 21:45
  • In the end i have " register_post_type( 'post_type_pros', $args );} add_action( 'init', 'custom_post_type_pros', 0 );" just a regular custom post type... – Ben Jan 4 '16 at 7:24
  • I suggest to use theme modifications and customizer API for theme options and the options API for plugin configuration. Why configure the plugin through theme options? Why to use a ACF to build a theme options page using some other API if WordPress already has a great theme options API (formely theme modifications API)? – cybmeta Jan 4 '16 at 8:15
  • I do need to use acf for a few reasons. but thanks for the suggestion! – Ben Jan 4 '16 at 16:12
  • It works as expected when I use an ACF option in post type registration on init, twentysixteen theme and no other plugins activated. – Milo Jan 4 '16 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.