Support

Account

Home Forums Backend Issues (wp-admin) Can't load templates in ACF (with Themosis) Reply To: Can't load templates in ACF (with Themosis)

  • Thanks John,

    This helped out. Although my options still aren’t working.. I get this error message:

    Undefined index: page_template
    Location:
    ...actions.php on line 81

    Underneath the two functions (the first one is also from my first post):

    add_filter('acf/location/rule_values/page_template', 'add_themosis_templates_to_acf_rules', 20);
    function add_themosis_templates_to_acf_rules($choices)
    {
        $key = 'theme';
        $configFile = 'templates.config.php';
        $configTemplates = include(themosis_path($key) . 'config' . DS . $configFile );
        $templates = array();
        foreach ($configTemplates as $configTemplate) {
            $prettyTemplateName = str_replace(array('-', '_'), ' ', ucfirst(trim($configTemplate)));
            $templates[$configTemplate] = $prettyTemplateName;
        }
        return array_merge(array('none' => __('None')), $templates);
    }
    
    // get themosis templates
    add_filter('acf/location/rule_match/page_template', 'get_themosis_templates_from_acf_rules', 11, 3);
    function get_themosis_templates_from_acf_rules($match, $rule, $options)
    {
        // vars
        $page_template = $options['page_template']; // This is line #81
        // get page template
        if (!$page_template && $options['post_id']) {
            $page_template = get_post_meta($options['post_id'], '_themosisPageTemplate', true);
        }
        // compare
        if ($rule['operator'] == "==") {
            $match = ($page_template === $rule['value']);
        } elseif ($rule['operator'] == "!=") {
            $match = ($page_template !== $rule['value']);
        }
        // return
        return $match;
    }