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' );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.