Support

Account

Home Forums Add-ons Options Page Register a Taxonomy if Option Field set to True Reply To: Register a Taxonomy if Option Field set to True

  • UPDATE: This is solved. In case anyone wants to register a taxonomy based upon an option field, here’s how to do it:

    function register_my_cpts_wed_vendors() {
    	$labels = array(
    		"name" => __( "Vendors", "wed" ),
    		"singular_name" => __( "Vendors", "wed" ),
    	);
    
    	$args = array(
    		"label" => __( "Vendors", "wed" ),
    		"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" => array( 'slug' => 'vendors', 'with_front' => true, ),
    		"show_admin_column" => true,
    		"show_in_rest" => true,
    		"rest_base" => "wed_vendors",
    		"rest_controller_class" => "WP_REST_Terms_Controller",
    		"show_in_quick_edit" => false,
    	);
    	register_taxonomy( "wed_vendors", array( "post", "wed_vendor"), $args );
    }
    
    add_action( 'register_wed_vendors','register_my_cpts_wed_vendors', 10, 2 );
    
    function wed_get_vendor_enable() {
    	$enablevendortax = get_field('enable_vendor_tax', 'option');
    	
    	if($enablevendortax=='1') {	
    		do_action('register_wed_vendors' );
    	}
    }
    
    add_action( 'init', 'wed_get_vendor_enable' );