Automatically generate final scores in title
-
I put between 50-100 scores into my SportsPress site every night and would like to automate the process of changing the title of events after the games go final. I do not know how to change the relevant code to get the desired outcome, but I’d like SportsPress to write the event title in the following format:
LEAGUE: WINNING TEAM xx, LOSING TEAM xx
if the title field is blank and score information is entered when the event is updated. That way all titles are entered correctly and uniformly every time, we get the final scores listed in the title of Google search results and the score can be automatically tweeted upon editing the event.Here is the relevant section of code that generates the team names in the event title.
* Auto-generate an event title based on the team playing if left blank. * * @param array $data * @return array */ public function wp_insert_post_data( $data, $postarr ) { if ( $data['post_type'] == 'sp_event' && $data['post_title'] == '' ): $teams = sp_array_value( $postarr, 'sp_team', array() ); $teams = array_filter( $teams ); $team_names = array(); foreach ( $teams as $team ): while ( is_array( $team ) ) { $team = array_shift( array_filter( $team ) ); } if ( $team > 0 ) $team_names[] = get_the_title( $team ); endforeach; $team_names = array_unique( $team_names ); $data['post_title'] = implode( ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ', $team_names ); endif; return $data; }
- The topic ‘Automatically generate final scores in title’ is closed to new replies.