• Resolved nimeck

    (@nimeck)


    Is there a shortcode that would list out all the matches to be played in a certain venue? Much like what is displayed on the Venue template page?

    I am trying to add a page with a little more info per venue and would like to include the matches at that venue at the bottom of the page. I can’t seem to find it in any documentation.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author AntoineH

    (@antoineh)

    There is not a shortcode yet, but the code to display the matches for a venue is fairly simple.

    $pool = new Football_Pool_Pool;
    $stadiums = new Football_Pool_Stadiums;
    
    $stadium = $stadiums->get_stadium_by_id( 1 );
    
    $fixtures = $stadium->get_plays();
    echo $pool->matches->print_matches( $fixtures, 'page stadium-page' );

    So, I went ahead and asked chatgpt to create a shortcode for me with this code ??

    This was the conversation:

    https://app.screencast.com/7qUY1Q5Q6kPfN

    and here’s the result:

    <?php
    /*
    Plugin Name: Stadium Matches Shortcode
    Description: This plugin adds a shortcode to display matches for a certain stadium.
    */
    
    // Main plugin class
    class Stadium_Matches_Shortcode {
        
        public function __construct() {
            // Hook to plugins_loaded to ensure dependencies are loaded
            add_action('plugins_loaded', array($this, 'init'));
        }
        
        // Initialize the plugin
        public function init() {
            // Add shortcode
            add_shortcode('stadium_matches', array($this, 'display_stadium_matches'));
        }
        
        // Shortcode function
        public function display_stadium_matches($atts) {
            // Instantiate Football Pool classes
            $pool = new Football_Pool_Pool;
            $stadiums = new Football_Pool_Stadiums;
    
            // Get stadium ID from shortcode attribute
            $stadium_id = isset($atts['stadium_id']) ? intval($atts['stadium_id']) : 1;
    
            // Get stadium details
            $stadium = $stadiums->get_stadium_by_id($stadium_id);
    
            // Get matches for the stadium
            $fixtures = $stadium->get_plays();
    
            // Return the matches using Football Pool's print_matches method
            return $pool->matches->print_matches($fixtures, 'page stadium-page');
        }
    }
    
    // Instantiate the plugin class
    new Stadium_Matches_Shortcode();

    Works pretty well ??

    Thread Starter nimeck

    (@nimeck)

    Wow, brilliant! Works.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List Matches by Venue Shortcode’ is closed to new replies.