Support

Account

Home Forums Backend Issues (wp-admin) Filtering relationship field depending on selected Post Type Reply To: Filtering relationship field depending on selected Post Type

  • Assuming that your posts do not have the field end

    
    add_filter('acf/fields/relationship/query/name=main_feature', function($options, $field, $post_id) {
        $options['post_status'] = array('publish');
            $options['meta_query'] = array(
                'relation' => 'OR',
                array(
                    'key' => 'end',
                    'compare' => '>=',
                    'value' =>  date('Y-m-d H:i:s'),
                    'type' => 'DATETIME'
                ),
                array(
                    'key' => 'end',
                    'compare' => 'NOT EXISTS'
                )
            );
        return $options;
    }, 10, 3);