Custom Fields
Re-Envisioned
Support Meta Box Conditional Logic build custom meta boxes for soccer matches

This topic contains 3 replies, has 2 voices, and was last updated by  Anh Tran 7 months, 2 weeks ago.

  • Creator
    Topic
  • #14088

    sadiq ahmed
    Participant

    hello

    i try to build mini website that i can add every match on new post and i want to use meta boxes .

    my idea is :
    editor first choose the league (ex : italy , spain , england … etc) then the second box the select box with all team show (this is for team1) then same for team 2 , i don’t want use deferent field for each league ,

    -2-
    can i get field value from API ? like i add (ID-field) and when i fill it with match ID from the API the other fields fill via API like , start time , location , country , stadium … etc

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #14091

    Anh Tran
    Keymaster

    Hi Sadiq,

    Regarding the first question, I think you can do that with Meta Box Group. You can create a repeatable group with fields: league, team 1, team 2, etc.

    Regarding the 2nd question, yes, you can get field value with helper functions or shortcode.

    #14094

    sadiq ahmed
    Participant

    hi

    thank you for the reply ,, can you explain more ? i read the doc. ,, i want only 2 teams on each post ! you mean add repeater for 2 teams and each repeater have the league & the team name ? then how i set the team name list on what the editor was choose ?

    if you please guide me with code example

    #14100

    Anh Tran
    Keymaster

    Hi Sadiq,

    Please try to follow these steps:

    1. Create a new custom post type for teams, you can use MB Custom Post Type to do this.
    2. Create a meta box like this:
    add_filter( 'rwmb_meta_boxes', function( $meta_boxes ) {
        $meta_boxes[] = [
            'title' => 'Matches',
            'fields' => [
                [
                    'id' => 'matches',
                    'type' => 'group',
                    'clone' => true,
                    'collapsible' => true,
                    'fields' => [
                        [
                            'id' => 'league',
                            'name' => 'League',
                            'type' => 'text',
                        ],
                        [
                            'id' => 'team1',
                            'name' => 'Team 1',
                            'type' => 'post',
                            'post_type' => 'team',
                        ],
                        [
    
                            'id' => 'team2',
                            'name' => 'Team 2',
                            'type' => 'post',
                            'post_type' => 'team',
                        ],
                    ],
                ],
            ],
        ];
    } );

    PS: Please take the code as a starter point and try to follow the docs for Meta Box and Meta Box Group. As you’re the one who knows what you want exactly, you should do the code. I can just only help, but can’t do that for you.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.