Coding of esport match plugin (2 posts)

  1. echofish
    Posted 3 years ago #


    I'll try to explain as detailed as possible, but my knowledge of php is very very limited and this is basically what my brain have successfully managed to grasp. I do realise there must be a much smarter way of doing this, so thats really why I'm posting here.

    I am trying to code an esport match plugin. Each match consists of two team and each of those two teams has 9 players (which differs every time). Each player should have one field (form) for Name, one for Origin, and 4 social fields where links to website/facebook/twitter/youtube should be available.

    I've tampered very little with php, and whilst I can understand some of it, I'm having a hard time writing the stuff myself. Below I've included one way I *figured* would work - although I haven't tried it myself yet (mainfunction is match).

    function match_teams(){
            add_meta_box( 'match_teams',
                'Match Teams',
                'match', 'normal', 'high'
        function display_match_teams(){
            global $post;
            $custom = get_post_custom($post->ID);
            $t1_p1_name = $custom["t1_p1_name"][0];
            $t1_p1_dep = $custom["t1_p1_dep"][0];
            $t1_p1_web = $custom["t1_p1_web"][0];
            $t1_p1_yt = $custom["t1_p1_yt"][0];
            $t1_p1_fb = $custom["t1_p1_fb"][0];
            $t1_p1_t = $custom["t1_p1_t"][0];
            $t1_p2_name = $custom["t1_p2_name"][0];
            $t1_p2_dep = $custom["t1_p2_dep"][0];
            $t1_p2_web = $custom["t1_p2_web"][0];
            $t1_p2_yt = $custom["t1_p2_yt"][0];
            $t1_p2_fb = $custom["t1_p2_fb"][0];
            $t1_p2_t = $custom["t1_p2_t"][0];

    And so on. Structure is tx_px_xxx (team1_player1_social).

    As you see, this would end up with a little bit over 100 variables and this -can not- be the optimal way of doing what I want. I can also imagine it will be unnecessarily difficult to save each of the variables in the database.

    In theory, I would want to make something that I later could output in wordpress as a loop that loops team one and team two but still retain the possibility of styling I have when I would output each variable.

    I would never request someone to code this for me, but I need some pointing in the right direction, even if it's a specific area of php I need to learn more about. I appreciate all help I can get as I feel pretty lost here. Thanks in advance!

  2. s_ha_dum
    Posted 3 years ago #

    Ok. I do not entirely understand what you are doing, but it looks like you have several components and are trying to save them in a giant monolithic block. I don't think you need to do that. For example, your players can be saved separately.

    $players['player-name-or-other-identifier'] = array(
        'name'   => 'Player Name',
        'origin' => 'Player Origin',
        'social' => array(
            'website'  => '',
            'facebook' => '',
            'twitter'  => ''
            'youtube'  => ''
    ); // repeat for each player

    You could save that array to *_options. Then when you make your matches you just need to save the teams, the team composition, and the player-name-or-other-identifier key, like:

    $teams['t1'] = array(
    $teams['t2'] = array(
    $match['match-identifier'] = array('t1','t2');

    You could even randomize like:

    $teams[t1] = array(array_rand($players,9));
    $teams[t2] = array(array_rand($players,9));

    That may look more complicated but I think it will actually simplify what you are doing by giving you more granular pieces to work with.

Topic Closed

This topic has been closed to new replies.

About this Topic