Support

Account

Forum Replies Created

  • With big thanks to Elliot for helping me figure this out, and for the benefit of anyone else who finds this, the main problem was wrapping acf.Condition in jQuery on ready.

    For testing purposes, this code works and can be added to a theme’s functions.php:

    add_action( 'acf/admin_footer', 'my_admin_footer' );
    function my_admin_footer() {
    ?>
    <script>
    (function( $ ) {
    	'use strict';
    	var HasTerm = acf.Condition.extend({
    		type: 'hasTerm',
    		operator: '==hasTerm',
    		label: acf.__('Has term'),
    		fieldTypes: [ 'taxonomy' ],
    		match: function( rule, field ){
    			return rule.value === field.val();
    		},
    		choices: function( fieldObject ){
    			return '<input type="text" />';
    		}
    	});
    	acf.registerConditionType( HasTerm );
    
    }( jQuery ));
    </script>
    <?php
    }
  • Just to add some more data for what works and doesn’t:

    – the acf/settings/select2_version filter doesn’t help
    – I also tried acf_update_setting('select2_version', 4 ); which didn’t work either
    – I am using WooCommerce, and it’s WC’s select2 which gets enqueued
    – when attempting to add a new repeating field set in a form in admin I get the same js error as reported by others
    – reverting to ACF 5.5.11 resolves the issue

  • I could dynamically load a select field, but unfortunately I’m already using some of the specific taxonomy field features in multiple places in my code (e.g. saving tax terms, using get_field to get full term object etc) so it would involve a fair bit of refactoring.

    Support suggested the same thing, or that I could create my own field type which would mean I don’t need to refactor any existing code.

    Either way looks like solving this will involve a fair bit of (re)coding 🙁 but at least I’m not missing something obvious.

    Thanks for your help.

  • Thanks John. The select2_init javascript hook might do the trick, but I’m not sure what to call… I’ll open a ticket and see what’s possible.

  • Thanks John. It’s a shame there’s not a straightforward way to use the ACF’s fantastic frontend for custom tables, but understandable given the potential complexity. I might explore hooking into update_post_meta(), or look at other options like Pods, or maybe the WordPress Fields API project.

  • In this particular instance, just hiding a single field is all I need, but I had completely missed that I can set up custom rules, which will certainly come in useful in other situations.

    Thank you!

  • Thank you @elliot – it was the ordering of things which caused the problem.

    I wasn’t able to order things right to get an acf options page as a submenu page of a non-ACF menu page, though I suspect it would work fine if I got the order right. I did, however, get my own submenu page as a submenu of the ACF Options menu page – which is what I was aiming for anyway.

    For the benefit of anyone else trying to do this here’s what worked for me:-

    function add_site_options()
    {
    	//add general site options menu
    	$parent_slug = 'acf-options';
    	$page_title = 'Site Tools';
    	$menu_title = 'Site Tools';
    	$capability = 'manage_options';
    	$menu_slug = 'site_options_tools';
    	$function = 'site_options_tools_html';
    	add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function);
    }
    add_action( 'admin_menu', 'add_site_options', 12 )
  • Thanks Elliot. Sorry if I wasn’t clear… but I wasn’t getting any ACF fields showing on the page I added with “acf_add_options_sub_page”. The name shown in the ‘location dropdown’ is “Site Options” which is the name I gave the sub menu page.

    I’m happy to do it another way altogether if that’s better – the core thing I am trying to achieve is to have an ACF submenu page and a standard WP submenu page under the same menu.

  • Well… I tried lots of different things. For example, the following got the menus in the right place, but no fields got added to the options page (the only rule option I have is Options Page = Site Options).

    	public function add_site_options()
    	{
    		//add section heading
    		$page_title = 'Site Tools';
    		$menu_title = 'Site Tools';
    		$capability = 'manage_options';
    		$menu_slug = 'site_options_tools';
    		$function = array( $this, 'site_options_tools_html' );
    		$icon_url = NULL;
    		$position = 500;
    		add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
    
    		//add general site options menu
    		$parent_slug = 'site_options_tools';
    		$page_title = 'Site Tools';
    		$menu_title = 'Site Tools';
    		$capability = 'manage_options';
    		$menu_slug = 'site_options_tools';
    		$function = array( $this, 'site_options_tools_html' );
    		add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function);
    	}
    
    	public function acf_options_setup()
    	{
    		if( function_exists('acf_set_options_page_menu') )
    		{
    			acf_set_options_page_menu( 'Site Options' );
    		}
    
    		if( function_exists('acf_add_options_sub_page') )
    		{
    			acf_add_options_sub_page(array(
    			                              'menu' => 'Site Options',
    			                              'title' => 'Site Options',
    			                              'slug' => 'acf_site_options',
    			                              'parent' => 'site_options_tools',
    			                              'capability' => 'manage_options'
    			                         ));
    		}
    	}
    		//in __construct()
    		$this->add_action( 'plugins_loaded', 'acf_options_setup' );
    		$this->add_action( 'admin_menu', 'add_site_options' );
Viewing 9 posts - 1 through 9 (of 9 total)