Support

Account

Forum Replies Created

  • Banging my head on the wall now. name= works. I made a stupid mistake and had a duplicate field in my functions with a slightly different name and I was calling the wrong one. Thanks so much elliot! It’s great to understand the filters now.

  • Sorry about that – I believe we have the correct use of the variable now, but it doesn’t seem to be working correctly. Here’s everything I know:

    • We’ve registered the field 'name' => 'select_waiting_list', with 'choices' => array(), in functions.php.
    • AFTER registering all fields, still in functions.php, we used the modified filter as follows…
    function get_waiting_lists( $field ) {
    	
    	$field['choices'] = array();
    
    		// Query Waiting Lists Products
    		$args = array(
    			'post_type' => 'memberpressproduct',
    			'orderby' => 'name',
    			'order' => 'ASC',
    			'posts_per_page' => -1,
    			'tax_query' => array(
    				array(
    					'taxonomy'  => 'topics',
    					'field'     => 'id',
    					'terms'     => '22',
    					'operator'  => 'IN'
    				),
    			)
    		);
    		$lists_array = get_posts( $args );
    		
    			foreach ( $lists_array as $list ) {
    				
    				$choices[$list->ID] = $list->post_title;
    			
    			}
    	
    	$field['choices'] = $choices;
    		
    	wp_reset_postdata();
    	
    	return $field;
    }
    
    add_filter('acf/load_field/name=select_waiting_list', 'get_waiting_lists');
    
    • In single.php, this function dumps array(1) { ["choices"]=> array(2) { [449]=> string(26) "Waiting List - Millionaire" [623]=> string(29) "Waiting List - Small Business" } }
    • I’m not sure how to double check the value of this variable when we need it – which is in the admin while creating/editing a custom post type. When that field loads there, we get the select box with -Select- and then an empty choice beneath it. When inspecting the code, we see <select id="acf-field-connect_waiting_list" class="select" name="fields[field_5272b350a4105]"><option value="null">- Select -</option><option value="choices"></option></select>

    Thank you again, so much, for your help sorting this out. You guys have such great support.

    – Ross

  • I guess I need to use a filter. I modified the function to the following (so $field holds that array I was talking about in the initial post) and added the filter but still no luck… Any ideas? I really appreciate your help!

    function get_waiting_lists( $field ) {
    	
    	$field = array();
    
    		// Query Waiting Lists Products
    		$args = array(
    			'post_type' => 'memberpressproduct',
    			'orderby' => 'name',
    			'order' => 'ASC',
    			'posts_per_page' => -1,
    			'tax_query' => array(
    				array(
    					'taxonomy'  => 'topics',
    					'field'     => 'id',
    					'terms'     => '22',
    					'operator'  => 'IN'
    				),
    			)
    		);
    		$lists_array = get_posts( $args );
    		
    			foreach ( $lists_array as $list ) {
    				
    				$field[$list->ID] = $list->post_title;
    			
    			}
    	
    	wp_reset_postdata();
    
    	return $field;
    }
    
    add_filter('acf/load_field/name=select_waiting_list', 'get_waiting_lists');
  • Thanks for the lead, Elliot! I have to believe that someone else has run across this and come up with a solution… Any way I could get some direction on what script to use in the function? Thanks so much for your help!

  • PHP export worked flawlessly. Simple steps for anyone else who comes across this thread:

    1) Network Activate Advanced Custom Fields
    2) Create Field Groups on the Main Site through the Custom Fields Menu.
    3) Use Custom Fields –> Export, select all field groups, Export to PHP
    4) Paste the PHP into your (child) theme’s functions.php
    5) Go back and trash the fields from the main site so there aren’t duplicates.

    You now have ACF fields available network-wide.

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