Let’s say for example that I’m creating a website for a sports club. And I’d like to offer the coaches and technical staff to be able to add tournements.

What I’d like to do with this data is ofcource display it on the Tournements page. Or maybe even a notification in the banner of the homepage “coming-up tournement: balblabla Tournement April 6th”.

At the moment I have a simple HTML table inside the website contents text editor of the Tournements page. But it’s not so easy for people with no HMTL knowledge to add a tournement. They would have to copy the and paste it and edit the data. That’s just horrible.

Does anyone has a solution that would solve my probolem? Thank you!

1 Answer
1

The WordPress way to organize this is to create separate post types for the tournaments, the games, and the participants.

Here is an example for the tournament post type registration:

add_action( 'wp_loaded', function() {

    register_post_type(
        'tournament',
        [
            'label' => __( 'Tournaments', 'tournaments' ),
            'labels' => [
                'name'                  => __( 'Tournaments', 'tournaments' ),
                'singular_name'         => __( 'Tournament', 'tournaments' ),
                'add_new'               => __( 'Add New', 'tournaments' ),
                'add_new_item'          => __( 'Add New Tournament', 'tournaments' ),
                'edit_item'             => __( 'Edit Tournament', 'tournaments' ),
                'new_item'              => __( 'New Tournament', 'tournaments' ),
                'view_item'             => __( 'View Tournament', 'tournaments' ),
                'view_items'            => __( 'View Tournaments', 'tournaments' ),
                'search_items'          => __( 'Search Tournaments', 'tournaments' ),
                'not_found'             => __( 'No tournaments found.', 'tournaments' ),
                'not_found_in_trash'    => __( 'No tournaments found in Trash.', 'tournaments' ),
                'parent_item_colon'     => __( 'Parent Tournament:', 'tournaments' ),
                'all_items'             => __( 'All Tournaments', 'tournaments' ),
                'archives'              => __( 'Tournament Archives', 'tournaments' ),
                'attributes'            => __( 'Tournament Attributes', 'tournaments' ),
                'insert_into_item'      => __( 'Insert into tournament', 'tournaments' ),
                'uploaded_to_this_item' => __( 'Uploaded to this tournament', 'tournaments' ),
                'featured_image'        => __( 'Banner', 'tournaments' ),
                'set_featured_image'    => __( 'Set banner', 'tournaments' ),
                'remove_featured_image' => __( 'Remove banner', 'tournaments' ),
                'use_featured_image'    => __( 'Use as banner', 'tournaments' ),
                'filter_items_list'     => __( 'Filter tournaments list', 'tournaments' ),
                'items_list_navigation' => __( 'Tournaments list navigation', 'tournaments' ),
                'items_list'            => __( 'Tournaments list', 'tournaments' ),
            ],
            'public' => TRUE,
            'hierarchical' =>TRUE,
            /*
             * 'edit_post' is now 'edit_tournament'
             * 'edit_posts' is now 'edit_tournaments'
             * Use these caabilities to set custom user capabilities, maybe
             * depending on the user role.
             */
            'capability_type' => [ 'tournament', 'tournaments' ],
            'map_meta_cap' => TRUE,
            'supports' => [
                'title',
                'editor',
                'comments',
                'revisions',
                'author',
                'excerpt',
                'page-attributes', // allows multiple custom tournament templates
                'thumbnail',
                'custom-fields'
            ],
            'has_archive' => __( 'tournaments', 'tournaments' ),
            'rewrite' => [
                'slug' => __( 'tournament', 'tournaments' ),
            ],
            'delete_with_user' => FALSE,
        ]
    );
});

As you can see, you can use some of the built-in features for that post type, like the featured image for the banner. You can also make this post type hierarchical to have “parent” pages for recurring tournaments, and separate pages for each year or month instance.

I would now also set up the games and players post types in a similar way (but not hierarchical, of course). Then I would register a custom user role for the people who are allowed to add or edit a tournament.

For the overview page use the archive template, in this case archive-tournament.php. See the Template Hierarchy for more information. Instead of the usual post list, you can easily build a table here. On each tournament page (single-tournament.php), you can list the games and the players, the start and end time, the price money and so on. For these data, use custom meta boxes on the tournament editor page.

This is just a raw concept. The actual implementation will take a while. Make sure to write the code manually, don’t use some “magical” post type UI plugin! The reason is that you very likely have to tweak this code over time; you should know every line thoroughly.

Leave a Reply

Your email address will not be published. Required fields are marked *