function match_title($title, $id = null)
{
    if (get_post_type($id) == 'wpcm_match') {
        $default_club = get_default_club();
        $title_format = get_match_title_format();
        $separator = get_option('wpcm_match_clubs_separator');
        $home_id = (int) get_post_meta($id, 'wpcm_home_club', true);
        $away_id = (int) get_post_meta($id, 'wpcm_away_club', true);
        $home_club = get_post($home_id);
        $away_club = get_post($away_id);
        if ($title_format == '%home% vs %away%') {
            $side1 = wpcm_get_team_name($home_club, $id);
            $side2 = wpcm_get_team_name($away_club, $id);
        } else {
            $side1 = wpcm_get_team_name($away_club, $id);
            $side2 = wpcm_get_team_name($home_club, $id);
        }
        $title = $side1 . ' ' . $separator . ' ' . $side2;
        return $title;
    }
    return $title;
}
 public function wp_insert_post_data($data, $postarr)
 {
     if ($data['post_type'] == 'wpcm_match' && $data['post_title'] == '') {
         $default_club = get_default_club();
         $title_format = get_match_title_format();
         $separator = get_option('wpcm_match_clubs_separator');
         $home_id = $_POST['wpcm_home_club'];
         $away_id = $_POST['wpcm_away_club'];
         $home_club = get_post($home_id);
         $away_club = get_post($away_id);
         if ($title_format == '%home% vs %away%') {
             $side1 = wpcm_get_team_name($home_club, $postarr['ID']);
             $side2 = wpcm_get_team_name($away_club, $postarr['ID']);
         } else {
             $side1 = wpcm_get_team_name($away_club, $postarr['ID']);
             $side2 = wpcm_get_team_name($home_club, $postarr['ID']);
         }
         $title = $side1 . ' ' . $separator . ' ' . $side2;
         $post_name = sanitize_title_with_dashes($postarr['ID'] . '-' . $title);
         $data['post_title'] = $title;
         $data['post_name'] = $post_name;
     }
     return $data;
 }
<?php

/**
 * Results Widget
 *
 * @author 		Clubpress
 * @package 	WPClubManager/Templates
 * @version     1.3.2
 */
global $post;
$postid = get_the_ID();
$format = get_match_title_format();
$sport = get_option('wpcm_sport');
$home_club = get_post_meta($postid, 'wpcm_home_club', true);
$away_club = get_post_meta($postid, 'wpcm_away_club', true);
$home_goals = get_post_meta($postid, 'wpcm_home_goals', true);
$away_goals = get_post_meta($postid, 'wpcm_away_goals', true);
if ($sport == 'gaelic') {
    $gaa_goals_home = get_post_meta($postid, 'wpcm_home_gaa_goals', true);
    $gaa_points_home = get_post_meta($postid, 'wpcm_home_gaa_points', true);
    $gaa_goals_away = get_post_meta($postid, 'wpcm_away_gaa_goals', true);
    $gaa_points_away = get_post_meta($postid, 'wpcm_away_gaa_points', true);
}
$played = get_post_meta($postid, 'wpcm_played', true);
$comps = get_the_terms($postid, 'wpcm_comp');
$comp_status = get_post_meta($postid, 'wpcm_comp_status', true);
$teams = get_the_terms($postid, 'wpcm_team');
if ($format == '%home% vs %away%') {
    $side1 = $home_club;
    $side2 = $away_club;
    if ($sport == 'gaelic') {
        /**
         * Show status widget
         */
        public function upcoming_matches_widget()
        {
            $club = get_default_club();
            $format = get_match_title_format();
            $year = date('Y');
            $week = date('W');
            // get matches
            $query_args = array('numberposts' => '-1', 'order' => 'ASC', 'orderby' => 'post_date', 'post_type' => 'wpcm_match', 'post_status' => array('future'), 'posts_per_page' => '-1', 'date_query' => array(array('year' => $year, 'week' => $week)));
            $query_args['meta_query'] = array('relation' => 'OR', array('key' => 'wpcm_home_club', 'value' => $club), array('key' => 'wpcm_away_club', 'value' => $club));
            $matches = get_posts($query_args);
            ?>

		<ul class="wpcm-matches-list">
		
		<?php 
            if ($matches) {
                foreach ($matches as $match) {
                    $home_club = get_post_meta($match->ID, 'wpcm_home_club', true);
                    $away_club = get_post_meta($match->ID, 'wpcm_away_club', true);
                    $timestamp = strtotime($match->post_date);
                    $time_format = get_option('time_format');
                    $neutral = get_post_meta($match->ID, 'wpcm_neutral', true);
                    $comps = get_the_terms($match->ID, 'wpcm_comp');
                    $comp_status = get_post_meta($match->ID, 'wpcm_comp_status', true);
                    $separator = get_option('wpcm_match_clubs_separator');
                    if ($format == '%home% vs %away%') {
                        $side1 = $home_club;
                        $side2 = $away_club;
                    } else {
                        $side1 = $away_club;
                        $side2 = $home_club;
                    }
                    if (is_array($comps)) {
                        foreach ($comps as $comp) {
                            $comp = reset($comps);
                            $t_id = $comp->term_id;
                            $comp_meta = get_option("taxonomy_term_{$t_id}");
                            $comp_label = $comp_meta['wpcm_comp_label'];
                            $competition = $comp->name . '&nbsp;' . $comp_status;
                        }
                    }
                    ?>

				<li class="wpcm-matches-list-item">

					<div class="wpcm-matches-list-link">
				
						<span class="wpcm-matches-list-col wpcm-matches-list-club1">
							<?php 
                    if ($club == $side1) {
                        echo '<strong>';
                    }
                    echo wpcm_get_team_name($side1, $match->ID);
                    if ($club == $side1) {
                        echo '</strong>';
                    }
                    ?>
						</span>

						<span class="wpcm-matches-list-col wpcm-matches-list-status">
							<span class="wpcm-matches-list-sep">
								<?php 
                    echo $separator;
                    ?>
							</span>
						</span>

						<span class="wpcm-matches-list-col wpcm-matches-list-club2">
							<?php 
                    if ($club == $side2) {
                        echo '<strong>';
                    }
                    echo wpcm_get_team_name($side2, $match->ID);
                    if ($club == $side2) {
                        echo '</strong>';
                    }
                    ?>
						</span>

					</div>

					<a href="<?php 
                    echo get_edit_post_link($match->ID);
                    ?>
" class="wpcm-matches-list-additional">

						<span class="wpcm-matches-list-additional-col wpcm-matches-list-date">
							<?php 
                    echo date_i18n('l jS F', $timestamp);
                    ?>
						</span>

						<span class="wpcm-matches-list-additional-col wpcm-matches-list-status">
							<span class="wpcm-matches-list-time">
								<?php 
                    echo date_i18n($time_format, $timestamp);
                    ?>
							</span>
						</span>

						<span class="wpcm-matches-list-additional-col wpcm-matches-list-info">
							<?php 
                    echo $competition;
                    ?>
						</span>

					</a>
				
				</li>

			<?php 
                }
            } else {
                ?>

			<li><?php 
                _e('No upcoming matches.', 'wp-club-manager');
                ?>
</li>

		<?php 
            }
            wp_reset_postdata();
            ?>

		</ul>

		<div class="add-new-match-link">
			<a class="button btn" href="post-new.php?post_type=wpcm_match"><?php 
            _e('Add New Match', 'wp-club-manager');
            ?>
</a>
		</div>

	<?php 
        }
    /**
     * Output the standings shortcode.
     *
     * @param array $atts
     */
    public static function output($atts)
    {
        extract(shortcode_atts(array(), $atts));
        $type = isset($atts['type']) ? $atts['type'] : '1';
        $title = isset($atts['title']) ? $atts['title'] : __('Fixtures & Results', 'wp-club-manager');
        $comp = isset($atts['comp']) ? $atts['comp'] : null;
        $season = isset($atts['season']) ? $atts['season'] : null;
        $team = isset($atts['team']) ? $atts['team'] : null;
        $month = isset($atts['month']) ? $atts['month'] : null;
        $venue = isset($atts['venue']) ? $atts['venue'] : null;
        $thumb = isset($atts['thumb']) ? $atts['thumb'] : null;
        $link_club = isset($atts['link_club']) ? $atts['link_club'] : null;
        $linktext = isset($atts['linktext']) ? $atts['linktext'] : __('View all results', 'wp-club-manager');
        $linkpage = isset($atts['linkpage']) ? $atts['linkpage'] : null;
        if ($comp <= 0) {
            $comp = null;
        }
        // if ( $season <= 0  )
        // 	$season = null;
        // if ( $team <= 0  )
        // 	$team = null;
        // if ( $venue <= 0  )
        // 	$venue = null;
        $club = get_default_club();
        // get matches
        $query_args = array('tax_query' => array(), 'numberposts' => '-1', 'order' => 'ASC', 'orderby' => 'post_date', 'post_type' => 'wpcm_match', 'post_status' => array('publish', 'future'), 'posts_per_page' => '-1');
        if (isset($club)) {
            $query_args['meta_query'] = array('relation' => 'OR', array('key' => 'wpcm_home_club', 'value' => $club), array('key' => 'wpcm_away_club', 'value' => $club));
        }
        if (isset($comp)) {
            $query_args['tax_query'][] = array('taxonomy' => 'wpcm_comp', 'terms' => $comp, 'field' => 'term_id');
        }
        if (isset($season)) {
            $query_args['tax_query'][] = array('taxonomy' => 'wpcm_season', 'terms' => $season, 'field' => 'term_id');
        }
        if (isset($team)) {
            $query_args['tax_query'][] = array('taxonomy' => 'wpcm_team', 'terms' => $team, 'field' => 'term_id');
        }
        if (isset($venue)) {
            $query_args['tax_query'][] = array('taxonomy' => 'wpcm_venue', 'terms' => $venue, 'field' => 'term_id');
        }
        if (isset($month)) {
            $query_args['date_query'] = array('month' => $month);
        }
        $matches = get_posts($query_args);
        ?>

		<?php 
        if ($matches) {
            if ($type == '2') {
                if ($title) {
                    echo '<h3>' . $title . '</h3>';
                }
                ?>

					<ul class="wpcm-matches-list">

			<?php 
            } else {
                ?>

				<div class="cp-table-wrap wpcm-fixtures-shortcode">

				<table class="cp-table cp-table-full">

				<?php 
                if ($title) {
                    echo '<caption>' . $title . '</caption>';
                }
                ?>

				<thead>
						
					<tr>
						<th class="wpcm-date"><?php 
                _e('Date', 'wp-club-manager');
                ?>
</th>
						<th class="venue"><?php 
                _e('Venue', 'wp-club-manager');
                ?>
</th>
						<?php 
                if ($thumb == '1') {
                    ?>
							<th class="club-thumb">&nbsp;</th>
						<?php 
                }
                ?>
						<th class="opponent"><?php 
                _e('Opponent', 'wp-club-manager');
                ?>
</th>
						<th class="competition"><?php 
                _e('Competition', 'wp-club-manager');
                ?>
</th>
						<th class="result"><?php 
                _e('Result', 'wp-club-manager');
                ?>
</th>
					</tr>

				</thead>
				<tbody>
			<?php 
            }
        } else {
            ?>

			<p><?php 
            _e('No matches played yet.', 'wp-club-manager');
            ?>
</p>

		<?php 
        }
        if ($matches) {
            foreach ($matches as $match) {
                // Get match data
                $sport = get_option('wpcm_sport');
                $format = get_match_title_format();
                $home_club = get_post_meta($match->ID, 'wpcm_home_club', true);
                $away_club = get_post_meta($match->ID, 'wpcm_away_club', true);
                $home_goals = get_post_meta($match->ID, 'wpcm_home_goals', true);
                $away_goals = get_post_meta($match->ID, 'wpcm_away_goals', true);
                if ($sport == 'gaelic') {
                    $home_gaa_goals = get_post_meta($match->ID, 'wpcm_home_gaa_goals', true);
                    $home_gaa_points = get_post_meta($match->ID, 'wpcm_home_gaa_points', true);
                    $away_gaa_goals = get_post_meta($match->ID, 'wpcm_away_gaa_goals', true);
                    $away_gaa_points = get_post_meta($match->ID, 'wpcm_away_gaa_points', true);
                }
                $played = get_post_meta($match->ID, 'wpcm_played', true);
                $timestamp = strtotime($match->post_date);
                $time_format = get_option('time_format');
                $neutral = get_post_meta($match->ID, 'wpcm_neutral', true);
                $comps = get_the_terms($match->ID, 'wpcm_comp');
                $comp_status = get_post_meta($match->ID, 'wpcm_comp_status', true);
                $match_link = get_post_permalink($match->ID, false, true);
                // Display Badge
                if ($thumb == '1') {
                    if (has_post_thumbnail($home_club)) {
                        $home_crest = '<td class="club-thumb">' . get_the_post_thumbnail($home_club, 'crest-small') . '</td>';
                    } else {
                        $home_crest = '<td class="club-thumb">' . wpcm_crest_placeholder_img('crest-small') . '</td>';
                    }
                    if (has_post_thumbnail($away_club)) {
                        $away_crest = '<td class="club-thumb">' . get_the_post_thumbnail($away_club, 'crest-small') . '</td>';
                    } else {
                        $away_crest = '<td class="club-thumb">' . wpcm_crest_placeholder_img('crest-small') . '</td>';
                    }
                } else {
                    $home_crest = '';
                    $away_crest = '';
                }
                // Display Outcome
                if ($home_goals == $away_goals) {
                    $outcome = '<span class="draw"></span>';
                    $class = 'draw';
                }
                if ($club == $home_club) {
                    if ($home_goals > $away_goals) {
                        $outcome = '<span class="win"></span>';
                        $class = 'win';
                    }
                    if ($home_goals < $away_goals) {
                        $outcome = '<span class="lose"></span>';
                        $class = 'loss';
                    }
                } else {
                    if ($home_goals > $away_goals) {
                        $outcome = '<span class="lose"></span>';
                        $class = 'loss';
                    }
                    if ($home_goals < $away_goals) {
                        $outcome = '<span class="win"></span>';
                        $class = 'win';
                    }
                }
                // Display venue and opponent
                if ($type == '1' && $club == $home_club) {
                    if ($neutral) {
                        $venue = __('N', 'wp-club-manager');
                    } else {
                        $venue = __('H', 'wp-club-manager');
                    }
                    $opponent = ($link_club ? '<a href="' . get_post_permalink($away_club, false, true) . '">' : '') . '' . get_the_title($away_club, true) . '' . ($link_club ? '</a>' : '');
                    $crest = $away_crest;
                } elseif ($type == '1' && $club == $away_club) {
                    if ($neutral) {
                        $venue = __('N', 'wp-club-manager');
                    } else {
                        $venue = __('A', 'wp-club-manager');
                    }
                    $opponent = ($link_club ? '<a href="' . get_post_permalink($home_club, false, true) . '">' : '') . '' . get_the_title($home_club, true) . '' . ($link_club ? '</a>' : '');
                    $crest = $home_crest;
                }
                // Display competition
                if (is_array($comps)) {
                    foreach ($comps as $comp) {
                        $comp = reset($comps);
                        $t_id = $comp->term_id;
                        $comp_meta = get_option("taxonomy_term_{$t_id}");
                        $comp_label = $comp_meta['wpcm_comp_label'];
                        if ($comp_label) {
                            $competition = $comp_label . '&nbsp;' . $comp_status;
                        } else {
                            $competition = $comp->name . '&nbsp;' . $comp_status;
                        }
                    }
                }
                // Display result - match.php Template
                if (get_option('wpcm_hide_scores') == 'yes' && !is_user_logged_in()) {
                    $result = $played ? __('x', 'wp-club-manager') . ' ' . get_option('wpcm_match_goals_delimiter') . ' ' . __('x', 'wp-club-manager') : '';
                } else {
                    if ($sport == 'gaelic') {
                        $result = ($played ? $home_gaa_goals . '-' . $home_gaa_points . ' ' . get_option('wpcm_match_goals_delimiter') . ' ' . $away_gaa_goals . '-' . $away_gaa_points : '') . ' ' . ($played ? $outcome : '');
                    } else {
                        $result = ($played ? $home_goals . ' ' . get_option('wpcm_match_goals_delimiter') . ' ' . $away_goals : '') . ' ' . ($played ? $outcome : '');
                    }
                }
                // Display status - match-2.php Template
                if ($played) {
                    $status_class = 'result';
                    if (get_option('wpcm_hide_scores') == 'yes' && !is_user_logged_in()) {
                        $status = __('x', 'wp-club-manager') . ' ' . get_option('wpcm_match_goals_delimiter') . ' ' . __('x', 'wp-club-manager');
                    } else {
                        if ($format == '%home% vs %away%') {
                            if ($sport == 'gaelic') {
                                $status = $home_gaa_goals . '-' . $home_gaa_points . ' ' . get_option('wpcm_match_goals_delimiter') . ' ' . $away_gaa_goals . '-' . $away_gaa_points;
                            } else {
                                $status = $home_goals . ' ' . get_option('wpcm_match_goals_delimiter') . ' ' . $away_goals;
                            }
                        } else {
                            if ($sport == 'gaelic') {
                                $status = $away_gaa_goals . '-' . $away_gaa_points . ' ' . get_option('wpcm_match_goals_delimiter') . ' ' . $home_gaa_goals . '-' . $home_gaa_points;
                            } else {
                                $status = $away_goals . ' ' . get_option('wpcm_match_goals_delimiter') . ' ' . $home_goals;
                            }
                        }
                    }
                } else {
                    $status_class = 'time';
                    $status = date_i18n($time_format, $timestamp);
                }
                // Display clubs format - match-2.php Template
                if ($format == '%home% vs %away%') {
                    $side1 = wpcm_get_team_name($home_club, $match->ID);
                    $side2 = wpcm_get_team_name($away_club, $match->ID);
                } else {
                    $side1 = wpcm_get_team_name($away_club, $match->ID);
                    $side2 = wpcm_get_team_name($home_club, $match->ID);
                }
                if ($type == '2') {
                    wpclubmanager_get_template('shortcodes/matches-2.php', array('match_link' => $match_link, 'timestamp' => $timestamp, 'status' => $status, 'status_class' => $status_class, 'competition' => $competition, 'side1' => $side1, 'side2' => $side2, 'class' => $class));
                } else {
                    wpclubmanager_get_template('shortcodes/matches.php', array('match_link' => $match_link, 'timestamp' => $timestamp, 'time_format' => $time_format, 'venue' => $venue, 'crest' => $crest, 'opponent' => $opponent, 'competition' => $competition, 'result' => $result, 'class' => $class));
                }
            }
        }
        if ($type == '2') {
            ?>

			</ul>

		<?php 
        } else {
            ?>

			</tbody>
			</table>
			</div>

		<?php 
        }
        if (isset($linkpage)) {
            ?>
		<a href="<?php 
            echo get_page_link($linkpage);
            ?>
" class="wpcm-view-link"><?php 
            echo $linktext;
            ?>
</a>
	<?php 
        }
    }