1

I am building a WP plugin and have integrated ACF (free version) as per the documentation on their website: https://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/

I also use a series of filters to load the ACF fields based on the location setting:

$this->loader->add_filter( 'acf/location/rule_types', $plugin_admin, 'acf_location_rules_types' );
$this->loader->add_filter( 'acf/location/rule_values/cpt', $plugin_admin, 'acf_location_rules_values_cpt' );
$this->loader->add_filter( 'acf/location/rule_match/cpt', $plugin_admin, 'acf_location_rules_match_cpt', 10, 3 );

This code is based on this simple plugin: https://github.com/lukechapman/custom-post-template-support-for-acf/blob/master/acf-custom-post-template-support.php

Everything has worked absolutely perfectly, but since I have upgraded to ACF pro this has completely stopped working.

I can't seem to find any resources specific to adding filters for ACF pro, only the basic version. I've debugged it and can confirm paths are correct, no errors in logs, and I also added some debug code to the first callback function acf_location_rules_types() and this is not being called at all.

The script that loads the filters is working, but it's like the filter options no longer exist in ACF Pro.

Where am I going wrong with this?

EDIT

I've also tried a very simple implementation like this which is also not being called:

add_filter('acf/location/rule_types', function ($rules) {
    error_log('acf/location/rule_types debug');
    return false;
});
2

1 Answer 1

0
<?php
// functions.php
add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices ) {
    $choices['Post']['post-type-has-taxonomy'] = __('Post Type has Taxonomy');
    return $choices;
}
add_filter( 'acf/location/rule_values/post-type-has-taxonomy', 'acf_location_rules_values_has_taxonomy' );
function acf_location_rules_values_has_taxonomy( $choices ) {
    return array_merge($choices, get_taxonomies());
}
add_filter('acf/location/rule_match/post-type-has-taxonomy', 'acf_location_rules_match_has_taxonomy', 10, 3);
function acf_location_rules_match_has_taxonomy( $match, $rule, $options )
{
    if ($rule['operator'] == '==') {
        $match = is_object_in_taxonomy($options['post_type'], $rule['value']);
    } elseif ($rule['operator'] == '!=') {
        $match = !is_object_in_taxonomy($options['post_type'], $rule['value']);
    }
    return $match;
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is what I have tried. The callback isn't being called.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.