-
Notifications
You must be signed in to change notification settings - Fork 258
Closed
Description
Version
- Carbon Fields: 3.3.0
- WordPress: 5.7.1
- PHP: 7.4
Expected Behavior
Show container if the custom post (price type) has the the 'price-cat-test' term (price_cat taxonomy) assigned to it. I've opened this issue in the past for CF 3.1.20 with WP 5.5 but it's been closed because others started talking about totally different things than the issue that I was describing and hasn't been answered back afterwards when I explained that it's still happening. See #927
Actual Behavior
Container never shows.
CPT definitions for quick testing
add_action('init', 'price_post_type', 0);
add_action('init', 'prices_taxonomy', 0);
function price_post_type() {
// Set UI labels for Custom Post Type
$labels = array(
'name' => _x( 'Prices', 'Post Type General Name', 'test' ),
'singular_name' => _x( 'Prices', 'Post Type Singular Name', 'test' ),
'menu_name' => _x( 'Prices', 'Admin Menu', 'test' ),
'name_admin_bar' => _x( 'Price', 'Add New On Admin Bar', 'test' ),
'all_items' => __( 'All Prices', 'test' ),
'view_item' => __( 'View Price', 'test' ),
'add_new_item' => __( 'Add Price', 'test' ),
'add_new' => __( 'Add New', 'test' ),
'edit_item' => __( 'Edit Price', 'test' ),
'update_item' => __( 'Update Price', 'test' ),
'search_items' => __( 'Search Price', 'test' ),
'not_found' => __( 'Not Found', 'test' ),
'not_found_in_trash' => __( 'Not found in Trash', 'test' )
);
// Set other options for Custom Post Type
$args = array(
'description' => __( 'Prices', 'test' ),
'labels' => $labels,
'supports' => array( 'title' ),
'hierarchical' => false,
'public' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 31,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => false,
'query_var' => false,
'rewrite' => false,
'taxonomies' => array('price_cat')
);
register_post_type( 'price', $args );
}
function prices_taxonomy() {
$labels = array(
'name' => _x( 'Price Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Price Categories', 'taxonomy singular name' ),
'search_items' => __( 'Search Price Categories' ),
'all_items' => __( 'All Price Categories' ),
'edit_item' => __( 'Edit Price Category' ),
'update_item' => __( 'Update Price Category' ),
'add_new_item' => __( 'Add New Price Category' ),
'new_item_name' => __( 'New Price Category Name' ),
'menu_name' => __( 'Price Categories' ),
);
register_taxonomy('price_cat', array('price'), array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'price-cat' )
));
}Container definition
Container::make( 'post_meta', 'Custom Data' )
->where( 'post_type', '=', 'price' )
->where( 'post_term', '=', array(
'field' => 'slug',
'value' => 'price-cat-test',
'taxonomy' => 'price_cat',
) )
->add_fields( array(
Field::make( 'text', 'heading', __( 'Heading' ) )
));Comments
I made some tests. It seems to be working fine (both in Gutenberg and Classic Editor modes) if I define the following container for a default post. The problem happens only for CPT and Taxonomies like I mentioned above. So the following one works for example:
Container::make( 'post_meta', 'Custom Data' )
->where( 'post_type', '=', 'post' )
->where( 'post_term', '=', array(
'field' => 'slug',
'value' => 'uncategorized',
'taxonomy' => 'category',
) )
->add_fields( array(
Field::make( 'text', 'heading', __( 'Heading' ) )
));Metadata
Metadata
Assignees
Labels
No labels