Support

Account

Home Forums Backend Issues (wp-admin) How to store custom taxonomies' values via ACF fields? Reply To: How to store custom taxonomies' values via ACF fields?

  • Hi John,

    Setting the meta_box_cb to false worked, thank you for that.

    For the save and load terms settings on the taxonomy, I need to add to the code for the custom taxonomies which i did not create using ACF – they are just coded.

    I looked and found that these should be the same as the settings in ACF:

    'capabilities'      => array(
    			'manage_terms'  => 'manage_trade_status',
    			'edit_terms'    => 'edit_trade_status',
    			'delete_terms'  => 'delete_trade_status',
    			'assign_terms'  => 'assign_trade_status'
    		)

    So i have added the above to the code for one of the taxes, and it does show the value on the post front end, but still does not save the value as seen in the admin columns. What else can i do or try?

    When i tried disabling the fields that are populated by the taxonomy terms, and creating them via ACF (because the settings you mentioned are right there), it created other issues like only getting the ID, instead of the value, and that would require lots of other coding to be changed in other places.

    Thanks.

    function cptui_register_my_taxes_trade_status() {
    
    	/**
    	 * Taxonomy: Trade Status.
    	 */
    
    	$labels = [
    		"name" => __( "Trade Status", "Avada" ),
    		"singular_name" => __( "Trade Status", "Avada" ),
    	];
    
    	
    	$args = [
    		"label" => __( "Trade Status", "Avada" ),
    		"labels" => $labels,
    		"public" => true,
    		"publicly_queryable" => true,
    		"hierarchical" => false,
    		"show_ui" => true,
    		"show_in_menu" => true,
    		"show_in_nav_menus" => true,
    		"query_var" => true,
    		"rewrite" => [ 'slug' => 'trade_status', 'with_front' => true, ],
    		"show_admin_column" => true,
    		"show_in_rest" => true,
    		"rest_base" => "trade_status",
    		"rest_controller_class" => "WP_REST_Terms_Controller",
    		"show_in_quick_edit" => true,
    		"show_in_graphql" => false,
    		"meta_box_cb" => false,
    		'capabilities'      => array(
    			'manage_terms'  => 'manage_trade_status',
    			'edit_terms'    => 'edit_trade_status',
    			'delete_terms'  => 'delete_trade_status',
    			'assign_terms'  => 'assign_trade_status'
    		)
    	];
    	register_taxonomy( "trade_status", [ "tradealert" ], $args );
    }
    add_action( 'init', 'cptui_register_my_taxes_trade_status' );
    
    /**
     * Populate the ACF field with terms from the custom taxonomy Trade Status type.
     */
    add_filter( 'acf/load_field/name=trade_status', function( $field ) {
      
        // Get all taxonomy terms
        $trade_status_options = get_terms( array(
          'taxonomy' => 'trade_status',
          'hide_empty' => false
        ) );
        
        // Add each term to the choices array.
        // Example: $field['choices']['review'] = Review
        foreach ( $trade_status_options as $option ) {
          $field['choices'][$option->slug] = $option->name;
        }
      
        return $field;
      } );