elementor icon indicating copy to clipboard operation
elementor copied to clipboard

Display condition does not load Custom Post types(manually added)

Open cenemil opened this issue 7 years ago • 3 comments

First of all, Elementor plugin has been essential in my projects and with it's sophisticated features, it made life easier. However, I have experienced a bug with display conditions. I have registered custom post types "Stores" and "Testimonials". Both of them doesn't show in the display conditions when I create a Single Template(type) so i got stuck with All Singular, Pages, etc(instances).

I've done some research and found out some answers here that there is a filter for including public post types for them to work and usable in Elementor templates instances.

add_filter( 'elementor_pro/utils/get_public_post_types', function() { $post_types['stores'] = 'Stores'; $post_types['testimonial'] = 'Testimonials'; return $post_types; } );

Is it by chance that i've done something wrong in my post type registration or Elementor only supports integrated CPT generator plugins?

cenemil avatar Feb 18 '19 18:02 cenemil

Hi @cenemil

Elementor conditions system supports custom post types out of the box. no extra configuration needed.

Simply make sure you are registering your post type with the proper options. e.g:

// Register Custom Post Type
function custom_post_type_test() {

	$labels = array(
		'name'                  => _x( 'Custom Post Types', 'Post Type General Name', 'cpt_test' ),
		'singular_name'         => _x( 'Custom Post Type', 'Post Type Singular Name', 'cpt_test' ),
		'menu_name'             => __( 'Custom Post Types', 'cpt_test' ),
		'name_admin_bar'        => __( 'Custom Post Type', 'cpt_test' ),
		'archives'              => __( 'Item Archives', 'cpt_test' ),
		'attributes'            => __( 'Item Attributes', 'cpt_test' ),
		'parent_item_colon'     => __( 'Parent Item:', 'cpt_test' ),
		'all_items'             => __( 'All Items', 'cpt_test' ),
		'add_new_item'          => __( 'Add New Item', 'cpt_test' ),
		'add_new'               => __( 'Add New', 'cpt_test' ),
		'new_item'              => __( 'New Item', 'cpt_test' ),
		'edit_item'             => __( 'Edit Item', 'cpt_test' ),
		'update_item'           => __( 'Update Item', 'cpt_test' ),
		'view_item'             => __( 'View Item', 'cpt_test' ),
		'view_items'            => __( 'View Items', 'cpt_test' ),
		'search_items'          => __( 'Search Item', 'cpt_test' ),
		'not_found'             => __( 'Not found', 'cpt_test' ),
		'not_found_in_trash'    => __( 'Not found in Trash', 'cpt_test' ),
		'featured_image'        => __( 'Featured Image', 'cpt_test' ),
		'set_featured_image'    => __( 'Set featured image', 'cpt_test' ),
		'remove_featured_image' => __( 'Remove featured image', 'cpt_test' ),
		'use_featured_image'    => __( 'Use as featured image', 'cpt_test' ),
		'insert_into_item'      => __( 'Insert into item', 'cpt_test' ),
		'uploaded_to_this_item' => __( 'Uploaded to this item', 'cpt_test' ),
		'items_list'            => __( 'Items list', 'cpt_test' ),
		'items_list_navigation' => __( 'Items list navigation', 'cpt_test' ),
		'filter_items_list'     => __( 'Filter items list', 'cpt_test' ),
	);
	$args = array(
		'label'                 => __( 'Custom Post Type', 'cpt_test' ),
		'description'           => __( 'Custom Post Type Description', 'cpt_test' ),
		'labels'                => $labels,
		'supports'              => array( 'title', 'editor', 'thumbnail' ),
		'taxonomies'            => array( 'category', 'post_tag' ),
		'hierarchical'          => false,
		'public'                => true,
		'show_ui'               => true,
		'show_in_menu'          => true,
		'menu_position'         => 5,
		'show_in_admin_bar'     => true,
		'show_in_nav_menus'     => true,
		'can_export'            => true,
		'has_archive'           => true,
		'exclude_from_search'   => false,
		'publicly_queryable'    => true,
		'capability_type'       => 'page',
	);
	register_post_type( 'cpt_test', $args );

}
add_action( 'init', 'custom_post_type_test', 0 );

We cannot debug it without inspecting your code.

Thanks.

shilo-ey avatar Feb 19 '19 07:02 shilo-ey

Thank you mate, made me realize my mistake in the CPT registration code

add_action( 'init', 'custom_store_post_type' ); function custom_store_post_type() { $labels = array( 'name' => __( 'Stores', 'Post Type General Name', 'hello-theme-child' ), 'singular_name' => __( 'Store', 'Post Type Singular Name', 'hello-theme-child' ), 'menu_name' => __( 'Stores', 'hello-theme-child' ), 'parent_item_colon' => __( 'Parent Item:', 'hello-theme-child' ), 'all_items' => __( 'All Stores', 'hello-theme-child' ), 'view_item' => __( 'View Store', 'hello-theme-child' ), 'add_new_item' => __( 'Add New Store', 'hello-theme-child' ), 'add_new' => __( 'Add New', 'hello-theme-child' ), 'edit_item' => __( 'Edit store', 'hello-theme-child' ), 'update_item' => __( 'Update store', 'hello-theme-child' ), 'search_items' => __( 'Search store', 'hello-theme-child' ), 'not_found' => __( 'Not found', 'hello-theme-child' ), 'not_found_in_trash' => __( 'Not found in Trash', 'hello-theme-child' ), ); $args = array( 'label' => __( 'Stores', 'hello-theme-child' ), 'description' => __( 'This is a custom post type for Stores.', 'hello-theme-child' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'thumbnail' ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'show_in_admin_bar' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-store', 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'page', ); register_post_type( 'store', $args ); }

If I change the "show_in_nav_menus" to TRUE, the Store cpt will be visible in the Display Conditions. I wonder why it happened? That line is intended for the Nav Menu screen. For now, i'll be extra careful with my CPT registration code.

cenemil avatar Feb 19 '19 13:02 cenemil

I had the same issue here! Why is this controlled via the 'show_in_nav_menus' option? Wouldn't it be clearer to use 'publicly_queryable'?

IlanVivanco avatar Jan 10 '24 15:01 IlanVivanco