Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1270957

    I tried putting this in my child theme’s functions.php, and it’s not throwing any errors, but it breaks the media library. Any ideas of how I could create a custom post type?

    <!-- new post type = Proud Bulldog Business -->
    <?php
    /*
    * Creating a function to create our CPT
    */
     
    function custom_post_type() {
     
    // Set UI labels for Custom Post Type
        $labels = array(
            'name'                => _x( 'Bulldog Businesses', 'Post Type General Name', 'twentytwenty' ),
            'singular_name'       => _x( 'Bulldog Business', 'Post Type Singular Name', 'twentytwenty' ),
            'menu_name'           => __( 'Bulldog Businesses', 'twentytwenty' ),
            'parent_item_colon'   => __( 'Parent Business', 'twentytwenty' ),
            'all_items'           => __( 'All Businesses', 'twentytwenty' ),
            'view_item'           => __( 'View Business', 'twentytwenty' ),
            'add_new_item'        => __( 'Add New Business', 'twentytwenty' ),
            'add_new'             => __( 'Add New', 'twentytwenty' ),
            'edit_item'           => __( 'Edit Business', 'twentytwenty' ),
            'update_item'         => __( 'Update Business', 'twentytwenty' ),
            'search_items'        => __( 'Search Business', 'twentytwenty' ),
            'not_found'           => __( 'Not Found', 'twentytwenty' ),
            'not_found_in_trash'  => __( 'Not found in Trash', 'twentytwenty' ),
        );
         
    // Set other options for Custom Post Type
         
        $args = array(
            'label'               => __( 'businesses', 'twentytwenty' ),
            'description'         => __( 'Proud Bulldog Businesses', 'twentytwenty' ),
            'labels'              => $labels,
            // Features this CPT supports in Post Editor
            'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
            // You can associate this CPT with a taxonomy or custom taxonomy. 
            'taxonomies'          => array( 'genres' ),
            /* A hierarchical CPT is like Pages and can have
            * Parent and child items. A non-hierarchical CPT
            * is like Posts.
            */ 
            'hierarchical'        => false,
            'public'              => true,
            'show_ui'             => true,
            'show_in_menu'        => true,
            'show_in_nav_menus'   => true,
            'show_in_admin_bar'   => true,
            'menu_position'       => 5,
            'can_export'          => true,
            'has_archive'         => true,
            'exclude_from_search' => false,
            'publicly_queryable'  => true,
            'capability_type'     => 'post',
            'show_in_rest' => true,
     
        );
         
        // Registering your Custom Post Type
        register_post_type( 'businesses', $args );
     
    }
     
    /* Hook into the 'init' action so that the function
    * Containing our post type registration is not 
    * unnecessarily executed. 
    */
     
    add_action( 'init', 'custom_post_type', 0 );
    ?>
    #1271157

    Okay so I got that part working, but what code do I need to add to include the ALB in the backend of this post type?

    #1271158

    Tried this from your documentation, but it only worked for a moment before the ALB option disappeared.

    function avf_alb_supported_post_types_mod( array $supported_post_types )
    {
    $supported_post_types[] = ‘Bulldog Businesses’;
    $supported_post_types[] = ‘Bulldog Businesses’;
    return $supported_post_types;
    }
    add_filter(‘avf_alb_supported_post_types’, ‘avf_alb_supported_post_types_mod’, 10, 1);

    • This reply was modified 3 years, 9 months ago by bucksharp.
    #1271763

    Hi,

    What is the actual slug of the Bulldog Businesses post type? In the avf_alb_supported_post_types filter, you have to use the slug of the post type instead of its name.

    // https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/#a-custom-slug-for-a-custom-post-type

    Example:

    function avf_alb_supported_post_types_mod( array $supported_post_types ) {
    	$supported_post_types[] = 'businesses';
    	return $supported_post_types;
    }
    add_filter('avf_alb_supported_post_types', 'avf_alb_supported_post_types_mod', 10, 1);
    

    Best regards,
    Ismael

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.