Support

Account

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

Solving

Can't load templates in ACF (with Themosis)

  • Hello,

    We have a website with Themosis framework and the latest version of ACF Pro (5.6.2). After the update from 5.5.14 to 5.6.2 we can’t locate templates anymore inside of ACF. Previously we loaded a list of all the templates in with the following code:

    add_filter('acf/location/rule_values/page_template', 'add_themosis_templates_to_acf_rules');
    function add_themosis_templates_to_acf_rules($choices)
    {
        $key = 'theme'; //modified
        $configFile = 'templates.config.php'; //modified
        $configTemplates = include(themosis_path($key) . 'config' . DS . $configFile ); //modified
        $templates = array();
        foreach ($configTemplates as $configTemplate) {
            $prettyTemplateName = str_replace(array('-', '_'), ' ', ucfirst(trim($configTemplate)));
            $templates[$configTemplate] = $prettyTemplateName;
        }
        return array_merge(array('none' => __('None')), $templates);
    }

    With the latest ACF update we only have the standard template. Is there a way to fix this? Are some classes changed within the latest version?

  • try changing the priority on your filter

    add_filter(‘acf/location/rule_values/page_template’, ‘add_themosis_templates_to_acf_rules’, 20);

  • 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;
    }
  • I don’t know what $options contains at this point. I do remember that there was some change in what’s passed to the filter because I created a filter not long ago and had some issues with that. You’re going to need to take a look at the values that ACF is passing to your filter.

  • At this time after editing a CPT post (which is not working) is giving me this values after printing $options:

    array(4) {
      'lang' =>
      string(0) ""
      'ajax' =>
      bool(false)
      'post_id' =>
      string(2) "62"
      'post_type' =>
      string(8) "training"
    }

    Going to try to debug some things

  • The problem is that $options['page_template'] is not set, what you need to do is remove this line $page_template = $options['page_template']; // This is line #81

  • Thanks for the answer. I checked if the options are available:

    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
        if (isset($options['page_template'])) {
            $page_template = $options['page_template'];
        }
    
        // get page template
        if (!isset($options['page_template']) && isset($options['post_id'])) {
            $page_template = get_post_meta($options['post_id'], '_themosisPageTemplate', true);
        }
        if (isset($page_template)) {
            // compare
            if ($rule['operator'] == "==") {
                $match = ($page_template === $rule['value']);
            } elseif ($rule['operator'] == "!=") {
                $match = ($page_template !== $rule['value']);
            }
        }
        
        // return
        return $match;
    }
  • This reply has been marked as private.
Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘Can't load templates in ACF (with Themosis)’ is closed to new replies.