Support

Account

Forum Replies Created

  • Yes it works – it works with a little bit knowledge using the perfect example from Hube – but it works also with standard ACF functions. You should use a standard select field with UI and AJAX activated. Your PHP action load_field should be set for this field and load the correct data. This is for both fields. Your second field should “hear” on $_POST[‘your_var_brand’] and then you should do a little bit work on your JS file…..

    Have a look at the ACF JavaScript API documentation. The keyword should be:

    acf.addFilter('select2_ajax_data', function( data, args, $input, field, instance )

    I have used this in my actual plugin project in 15 fields and it works great.

  • @hube2 thanks for your idea but this is all a very “unbeautiful” solution but it would work – i have tested with “tweaking” the relationship a little to add “hide_empty” true and tested it. But now i found a bug and opened a support case:

    I found in line includes\libraries\acf\includes\fields\class-acf-field-relationship.php on line 421: $terms = acf_get_grouped_terms( $term_args );
    and i followed the function to api-term.php to line 171. In line 181 i changed ‘hide_empty’ to true and give it a try -> it works BUT here seems to be a BUG:

    all taxonomies and their corresponding terms are shown (which are not empty). BUT 2 taxonomies (screenshot) are shown because there is in each one “filled term” but not the term itself. I think the problem is the “same” taxonomie name like für posts. but its only the “label” the same not the taxonomy name. It is “dpf_work_category” and “dpf_work_type” – i think there is the bug.

    I changed the registered name from one taxonomy from “dpf_work_category” to “dpf_work_category2” and than the missing term is shown under the category name. SO i think its a bug while checking the taxonomy name against the wordpress built-in category names…..

  • The relationship field shows “if activated” all taxonomies with their corresponding terms objects. But it shows ALL terms. Therefore my question. The first try was to define taxononomies in the PHP section for these fields but i have to define not the taxonomy but taxonomy:term for every allowed selection. This is not very handy. I could generate my own list and push it in the “load_field” section but it would be more useful to have an action or filter to hide the empty TERMS – or if all terms are empty the corresponding taxonomy.

  • I forgot that you have to define the associated translations via normal PHP with:

    		acf_localize_text(array(
    			'the results could not be loaded.'	=> _x( 'The results could not be loaded.', 'Select2', 'picture-frame' ),
    			'please delete'						=> _x( 'Please delete', 'Select2', 'picture-frame' ),
    			'character'							=> _x( 'character', 'Select2', 'picture-frame' ),
    			'please enter'						=> _x( 'Please enter', 'Select2', 'picture-frame' ),
    			'or more characters'				=> _x( 'or more characters', 'Select2', 'picture-frame' ),
    			'loading more results…'				=> _x( 'Loading more results…', 'Select2', 'picture-frame' ),
    			'you can only select'				=> _x( 'You can only select', 'Select2', 'picture-frame' ),
    			'item'								=> _x( 'item', 'Select2', 'picture-frame' ),
    			'no results found'					=> _x( 'No results found', 'Select2', 'picture-frame' ),
    			'searching...'						=> _x( 'Searching...', 'Select2', 'picture-frame' ),
    			'remove all items'					=> _x( 'Remove all items', 'Select2', 'picture-frame' ),
    			'remove item'						=> _x( 'Remove item', 'Select2', 'picture-frame' ),
    			'search'							=> _x( 'Search', 'Select2', 'picture-frame' ),
    		));
  • thats the way it works for a checkbox:

    $('#acf-field_pf_exhibition_zone_updated').prop('checked',false).trigger('change');

  • I have actually the same problem by set a hidden checkbox to false but the conditional rules are not applied to the dependend fields.

  • Another problem is: How could i tell the relationship field to get only taxonomies and terms which are not empty OR based on the filtered posts.

    Actually all elements of my taxonomies are shown – not depending on the filtered posts. But i couldnt find a hook to filter the taxonomies for the relationship field. Actually i can only filter the posts. Is there a hack or workaound?

  • Your documented filter relationship_ajax_data exists and its working perfect! But like i do it with the select2 fields to “change” my result, i want to do the same with the relationship field. But the _result doesnt exist and therefore i asked for a solution.

    My target is to “disable” options in one relationship field if this item is selected in another. Bases on the query i couldnt do this easy with HTML and it would be better to modify the result coming via AJAX.

  • There exist no relationship_ajax_result like for the select2 fields?? – is there another filter which i had to choose? Thanks for an answer.

  • I found a “more easy” solution for the translation problem of select 2 without using acf.addAction('select2_init'.

    I changed:

    $.fn.select2.amd.define('select2/i18n/xx',[],function () {

    to this:

    $.fn.select2.amd.define('select2/i18n/' + your-var-array.your-locale-2-char-languange,[],function () {

    and now it works perfect by using the acf.__('no results found');-function and pulling the right translations direct from my plugin mo/po files.

  • The hook acf.addAction('select2_init', function( $select, args, settings, field ){ is perfect and it would allow me to assign the correct language settings to all fields by using args['language'] = 'xx'; and by integrating this

    $.fn.select2.amd.define('select2/i18n/xx',[],function () {
      return {
        errorLoading: function () {
          return acf.__('the results could not be loaded.');
        },
        inputTooLong: function (args) {
          var overChars = args.input.length - args.maximum;
    
          var message = acf.__('please delete') + ' ' + overChars + ' ' + acf.__('character');
    
          if (overChars != 1) {
            message += 's';
          }
    
          return message;
        },
        inputTooShort: function (args) {
          var remainingChars = args.minimum - args.input.length;
    
          var message = acf.__('please enter') + ' ' + remainingChars + ' ' + acf.__('or more characters');
    
          return message;
        },
        loadingMore: function () {
          return acf.__('loading more results…');
        },
        maximumSelected: function (args) {
          var message = acf.__('you can only select') + ' ' + args.maximum + ' ' + acf.__('item');
    
          if (args.maximum != 1) {
            message += 's';
          }
    
          return message;
        },
        noResults: function () {
          return acf.__('no results found');
        },
        searching: function () {
          return acf.__('searching...');
        },
        removeAllItems: function () {
          return acf.__('remove all items');
        },
        removeItem: function () {
          return acf.__('remove item');
        },
        search: function() {
          return acf.__('search');
        }
      };
    });

    but the new problem is that now all select2 fields have more hight than before – it seems that they lost the styling…….

  • Actually its still not working. This is a part from select2.full.js

    ` },
    noResults: function () {
    return ‘No results found’;
    },
    searching: function () {
    return ‘Searching…’;
    },
    removeAllItems: function () {
    return ‘Remove all items’;
    },

  • Hello John,

    I could not really understand your answer! A group packs some fields together. The normal layout in a group is completely the same like using normal fields without a group. You are right that in a group the user could organize “more” but a group is like a titel with the correspondimg subfields -> with the same layout – only the “not beautiful GROUP-BORDER” bit thats only a little bit CSS and the look and feel is like in normal ACF-input-forms in the backend. BUT i need a group to could make a clone of “master”-fields which in need:
    1. in options
    2. in the main custom post type
    3. in the sub post type

    Based on the not so pefect ACF-layout i decided to put the instructions UNDER the field bacause thats make it more easy to handle the translations which need perhaps a little bit more chars than the orginal english one. Now my new group handles the instructions under the label – You say based on the group they are all now under the fields – YES thats what i need. Like in normal fields. And there is no case why this its not working. If you want i could make some screenshots of this.

    Regards André

  • After a long search here in support articles and in the web including github i have already some open questions about this solution:

    In my project i have one repeater field which i had to dynamically adjust based on another value. While using “load_field” it works perfect by setting [min] and [max] to the value i need (the value from another field).

    But i want to set this value on the edit page too – that means i change one field – i have a new value and now: change the rows…..

    I cant get it work! the add() function only works when the repeater field has NO settings for min and max. I tried a lot but with no result.

    It would be great to get help.

  • It was my fault !!!!!: By defining acf/save_post and NOT differentiating the ‘pages’ the WordPres AJAX goes into ‘the neverending search’. Now i switched to filter by pages/posttypes/categories and it works perfect.

  • This is my main plugin class:

    <?php
    /**
     * The file that defines the core plugin class
     *
     * A class definition that includes attributes and functions used across both the
     * public-facing side of the site and the admin area.
     *
     * @link       https://example.com
     * @since      1.0.0
     *
     * @package    Plugin_Name
     * @subpackage Plugin_Name/includes
     */
    
    /**
     * The core plugin class.
     *
     * This is used to define internationalization, admin-specific hooks, and
     * public-facing site hooks.
     *
     * Also maintains the unique identifier of this plugin as well as the current
     * version of the plugin.
     *
     * @since      1.0.0
     * @package    Plugin_Name
     * @subpackage Plugin_Name/includes
     * @author     Your Name <[email protected]>
     */
    class Picture_Frame {
    
    	/**
    	 * Store plugin main class to allow public access.
    	 *
    	 * @since    1.0.0
    	 * @var object      The main class.
    	 */
    	public $main;
    	
    	/**
    	 * Store plugin admin class to allow public access.
    	 *
    	 * @since    20180622
    	 * @var object      The admin class.
    	 */
    	public $admin;
    	
    	/**
    	 * Store plugin public class to allow public access.
    	 *
    	 * @since    20180622
    	 * @var object      The admin class.
    	 */
    	public $shared;
    
    	/**
    	 * Store plugin public class to allow public access.
    	 *
    	 * @since    20180622
    	 * @var object      The admin class.
    	 */
    	public $public;
    	
    	/**
    	 * The loader that's responsible for maintaining and registering all hooks that power
    	 * the plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   protected
    	 * @var      Plugin_Name_Loader    $loader    Maintains and registers all hooks for the plugin.
    	 */
    	protected $loader;
    
    	/**
    	 * The unique identifier of this plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   protected
    	 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
    	 */
    	protected $plugin_name;
    
    	/**
    	 * The unique prefix of this plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   protected
    	 * @var      string    $plugin_prefix    The string used to uniquely prefix technical functions of this plugin.
    	 */
    	protected $plugin_prefix;
    
    	/**
    	 * The current version of the plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   protected
    	 * @var      string    $version    The current version of the plugin.
    	 */
    	protected $version;
    
    	/**
    	 * Define the core functionality of the plugin.
    	 *
    	 * Set the plugin name and the plugin version that can be used throughout the plugin.
    	 * Load the dependencies, define the locale, and set the hooks for the admin area and
    	 * the public-facing side of the site.
    	 *
    	 * @since    1.0.0
    	 */
    	public function __construct() {
    
    		if ( defined( 'PICTURE_FRAME_VERSION' ) ) {
    
    			$this->version = PICTURE_FRAME_VERSION;
    
    		} else {
    
    			$this->version = '1.0.0';
    
    		}
    		
    		$this->main = $this;
    
    		$this->plugin_name = 'picture-frame';
    		$this->plugin_prefix = 'pfx_';
    
    		$this->load_dependencies();
    		$this->set_locale();
    		$this->define_admin_hooks();
    		$this->define_public_hooks();
    
    	}
    
    	/**
    	 * Load the required dependencies for this plugin.
    	 *
    	 * Include the following files that make up the plugin:
    	 *
    	 * - Plugin_Name_Loader. Orchestrates the hooks of the plugin.
    	 * - Plugin_Name_i18n. Defines internationalization functionality.
    	 * - Plugin_Name_Admin. Defines all hooks for the admin area.
    	 * - Plugin_Name_Public. Defines all hooks for the public side of the site.
    	 *
    	 * Create an instance of the loader which will be used to register the hooks
    	 * with WordPress.
    	 *
    	 * @since    1.0.0
    	 * @access   private
    	 */
    	private function load_dependencies() {
    		
    		/**
    		 * The class responsible for defining all actions that 
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-acf.php';
    
    		/**
    		 * The class responsible for orchestrating the actions and filters of the
    		 * core plugin.
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-loader.php';
    
    		/**
    		 * The class responsible for defining internationalization functionality
    		 * of the plugin.
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-i18n.php';
    		
    		/**
    		 * The class responsible for defining all actions that 
    		 */
    		 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-cpt.php';
    		
    		/**
    		 * The class for generating dropdowns in custom post types admin
    		 */
    		//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/libraries/walker.php';
    		
    		/**
    		 * Template Loader
    		 */
    		//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-template-loader.php';
    
    		/**
    		 * The class responsible for defining all actions that occur in the admin area.
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-picture-frame-admin.php';
    
    		/**
    		 * The class responsible for defining all actions that occur in the public-facing
    		 * side of the site.
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-picture-frame-public.php';
    		
    		/**
    		 * The class responsible for defining all actions that occur in admin and public area.
    		 */
    		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-shared.php';
    		
    		/**
    		 * The class responsible for generating the help sections.
    		 */
    		//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/libraries/class-contextual-help.php';
    		
    		/**
    		 * The class responsible for defining all help sections that occur in admin area.
    		 */
    		//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-help.php';
    
    		$this->loader = new Picture_Frame_Loader();
    
    	}
    
    	/**
    	 * Define the locale for this plugin for internationalization.
    	 *
    	 * Uses the Plugin_Name_i18n class in order to set the domain and to register the hook
    	 * with WordPress.
    	 *
    	 * @since    1.0.0
    	 * @access   private
    	 */
    	private function set_locale() {
    
    		$plugin_i18n = new Picture_Frame_I18n();
    
    		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
    
    	}
    
    	/**
    	 * Register all of the hooks related to the admin area functionality
    	 * of the plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   private
    	 */
    	private function define_admin_hooks() {
    
    		$this->admin	= new Picture_Frame_Admin( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    		$this->cpt		= new Picture_Frame_CPT( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    		//$this->acf		= new Picture_Frame_ACF( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    		$this->shared	= new Picture_Frame_Shared( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    		//$this->help		= new Picture_Frame_Help( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    
    		//$this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_styles' );
    		//$this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_scripts' );
    		
    		$this->loader->add_action( 'admin_menu', $this->admin, 'pf_create_menu' );
    		
    		// add custom post types and taxonomies
    		$this->loader->add_action( 'init', $this->cpt, 'pf_create_cpt' );
    		
    		// create fake submenu to add other taxonomies
    		$this->loader->add_action( 'admin_menu', $this->cpt, 'pf_create_submenus' );
    		
    		// highlight correct menu for taxonomies
    		//$this->loader->add_action( 'parent_file', $this->cpt, 'pf_highlight_menu' );
    		
    		//$this->loader->add_action( 'submenu_file', $this->cpt, 'pf_highlight_submenu' );
    		
    		// add columns to cpt exhibition
    		//$this->loader->add_filter( 'manage_pf_exhibition_posts_columns', $this->cpt, 'pf_add_columns_to_exhibition' );
    		
    		// fill columns in cpt exhibition
    		//$this->loader->add_action( 'manage_pf_exhibition_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_exhibition', 10, 2 );
    		
    		// add columns to cpt work
    		//$this->loader->add_filter( 'manage_pf_work_posts_columns', $this->cpt, 'pf_add_columns_to_work' );
    		
    		// fill columns in cpt work
    		//$this->loader->add_action( 'manage_pf_work_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_work', 10, 2 );
    	
    		// add columns to taxonomy artist
    		//$this->loader->add_filter( 'manage_edit-pf_work_artist_columns', $this->cpt, 'pf_add_columns_to_taxonomy_artist' );
    		
    		// fill columns in artist taxonomy
    		//$this->loader->add_filter( 'manage_pf_work_artist_custom_column', $this->cpt, 'pf_add_columns_content_to_taxonomy_artist', 10, 3 );
    		
    		// add columns to taxonomy artist
    		//$this->loader->add_filter( 'manage_edit-pf_work_client_columns', $this->cpt, 'pf_add_columns_to_taxonomy_client' );
    		
    		// fill columns in artist taxonomy
    		//$this->loader->add_filter( 'manage_pf_work_client_custom_column', $this->cpt, 'pf_add_columns_content_to_taxonomy_client', 10, 3 );
    		
    		// add columns to cpt zone
    		//$this->loader->add_filter( 'manage_pf_zone_posts_columns', $this->cpt, 'pf_add_columns_to_zone' );
    		
    		// fill columns in cpt screen
    		//$this->loader->add_action( 'manage_pf_zone_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_zone', 10, 2 );
    		
    		// add columns to cpt screen
    		//$this->loader->add_filter( 'manage_pf_display_posts_columns', $this->cpt, 'pf_add_columns_to_display' );
    		
    		// fill columns in cpt screen
    		//$this->loader->add_action( 'manage_pf_display_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_display', 10, 2 );
    		
    		// add columns to cpt view
    		//$this->loader->add_filter( 'manage_pf_view_posts_columns', $this->cpt, 'pf_add_columns_to_view' );
    		
    		// fill columns in cpt screen
    		//$this->loader->add_action( 'manage_pf_view_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_view', 10, 2 );
    		
    		// register sortable columns / dropdowns for post type
    		//$this->loader->add_action( 'restrict_manage_posts', $this->cpt, 'pf_filter_post_type_by_taxonomy' );
    		
    		// hide taxonomies from quick edit
    		//$this->loader->add_action( 'quick_edit_show_taxonomy', $this->cpt, 'pf_hide_taxonomies_quick_edit', 10, 3 );
    		
    		// add custom image sizes
    		//$this->loader->add_action( 'after_setup_theme', $this->admin, 'pf_add_image_sizes' );
    		
    		// add styles to admin head for custom post types
    		//$this->loader->add_action( 'admin_head', $this->admin, 'pf_add_styles_to_admin_head' );
    		
    		// delete attachement
    		//$this->loader->add_action( 'deleted_post', $this->admin, 'pf_delete_transients' );
    		
    		// add custom post type works to doashboard
    		//$this->loader->add_action( 'dashboard_glance_items', $this->cpt, 'pf_add_glance_content' );
    		
    		// add help screens for all plugin pages
    		//$this->loader->add_action( 'init', $this->help, 'pf_add_help' );
    		
    	}
    
    	/**
    	 * Register all of the hooks related to the public-facing functionality
    	 * of the plugin.
    	 *
    	 * @since    1.0.0
    	 * @access   private
    	 */
    	private function define_public_hooks() {
    
    		$this->public	= new Picture_Frame_Public( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    		$this->shared	= new Picture_Frame_Shared( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
    
    		$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'enqueue_styles' );
    		$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'enqueue_scripts' );
    		
    		$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'pf_enqueue_styles' );
    		$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'pf_enqueue_scripts' );
    
    		// Shortcode name must be the same as in shortcode_atts() third parameter.
    		//$this->loader->add_shortcode( $this->get_plugin_prefix() . 'shortcode', $this->public, 'pfx_shortcode_func' );
    		
    		// loads the custom template file for custom post type single public view
    		$this->loader->add_filter( 'single_template', $this->public, 'pf_get_template' );
    
    	}
    
    	/**
    	 * Run the loader to execute all of the hooks with WordPress.
    	 *
    	 * @since    1.0.0
    	 */
    	public function run() {
    		$this->loader->run();
    	}
    
    	/**
    	 * The name of the plugin used to uniquely identify it within the context of
    	 * WordPress and to define internationalization functionality.
    	 *
    	 * @since     1.0.0
    	 * @return    string    The name of the plugin.
    	 */
    	public function get_plugin_name() {
    		return $this->plugin_name;
    	}
    
    	/**
    	 * The unique prefix of the plugin used to uniquely prefix technical functions.
    	 *
    	 * @since     1.0.0
    	 * @return    string    The prefix of the plugin.
    	 */
    	public function get_plugin_prefix() {
    		return $this->plugin_prefix;
    	}
    
    	/**
    	 * The reference to the class that orchestrates the hooks with the plugin.
    	 *
    	 * @since     1.0.0
    	 * @return    Plugin_Name_Loader    Orchestrates the hooks of the plugin.
    	 */
    	public function get_loader() {
    		return $this->loader;
    	}
    
    	/**
    	 * Retrieve the version number of the plugin.
    	 *
    	 * @since     1.0.0
    	 * @return    string    The version number of the plugin.
    	 */
    	public function get_version() {
    		return $this->version;
    	}
    
    }
  • i am missing the “perfect” solution by ACF, but thanks for your way to do it in the right direction.

    I want to include it in the boilerplate too and “feel” that it could be not the perfect way. I used your direction in the start of my plugin development but now i try to build it new from a blank template and want to do it “in a perfect way”. Your direction is good but i missed the point to create the needed fields – in my old version i add a function “create fields” and called this in boilerplate admin hooks – i think there must be a better solution? Is this right?

    Calling the creating fields function in init was not possible for me because some included functions havent worked for me and so i called it in the admin hooks but where is the better solution?

    I miss a guide from ACF for perfect integration. They want to sell the plugin and should do a little bit more for the developers.

Viewing 20 posts - 1 through 20 (of 20 total)