Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( ! defined( 'ABSPATH' ) ) exit;
- class Digitalis_OXY_ACF {
- public function __construct() {
- $this->add_filters();
- }
- private function add_filters() {
- add_filter('acf/location/rule_types', [$this, 'location_rules']);
- add_filter('acf/location/rule_values/oxy-template', [$this, 'location_values_oxy_template']);
- add_filter('acf/location/rule_match/oxy-template', [$this, 'location_match_oxy_template'], 10, 4);
- }
- public function location_rules ( $choices ) {
- $choices['Oxygen']['oxy-template'] = 'Oxygen Template';
- return $choices;
- }
- function location_values_oxy_template ( $choices ) {
- global $wpdb;
- $templates = $wpdb->get_results(
- "SELECT id, post_title
- FROM $wpdb->posts as post
- WHERE post_type = 'ct_template'
- AND post.post_status IN ('publish')"
- );
- if( $templates ) {
- foreach($templates as $template) {
- $choices[ $template->id ] = $template->post_title;
- }
- }
- return $choices;
- }
- public function location_match_oxy_template ( $match, $rule, $options, $field_group = false ) {
- $current_template = get_post_meta( $options['post_id'], 'ct_other_template', true );
- $selected_template = (int) $rule['value'];
- if($rule['operator'] == "=="){
- $match = ( $current_template == $selected_template );
- } elseif($rule['operator'] == "!=") {
- $match = ( $current_template != $selected_template );
- }
- return $match;
- }
- }
- new Digitalis_OXY_ACF();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement