Support Forum
Support › Meta Box Conditional Logic › build custom meta boxes for soccer matches
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
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.
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
Hi Sadiq,
Please try to follow these steps:
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.