Support

Account

Home Forums Front-end Issues Multiple nested fields in one post, don't want to display all data

Solving

Multiple nested fields in one post, don't want to display all data

  • Hello,

    I am building a non usual website with advanced custom fields. I have made a group with nested repeater fields because of all the variations i have to make.
    And now i have completed the backend structure and was moving on to the frontend. Let me try to explain.

    It will be a (dutch) website about visa applications. So i have created a new CPT for nationalities and use a single template file to display the data. But i dont want to display all the entered data at once.
    In the backend i can add a country with 5 options with taxonomy fields attached. My purpose is to show only the cost and set of rules, which are other posts through selected country,nationality,visa kind, duration of stay.
    Backend structure

    In total i have about 195 countries and each country has about 20 records.
    That means 195 posts (CPT nationality) * 195 countries * 20 records.

    I have created a single template for the CPT. I can output the subfields etc. as in a ‘normal’ post. I cannot use the standard functions like get_sub_field(). Actually what i need is the get_field / get_sub_field functions combined with a value. So it displays the field with the desired value.

    Does anyone knows if this is possible?
    Is this the right approach to make such a website with advanced custom fields? Or am i on the wrong track and should i use another plugin?

  • Hi @redcat

    I’m afraid I don’t understand the issue. Could you please share the JSON export file of your field group so I can check your setup?

    Also, could you please let me know the current result and how you want it to be?

    Please keep in mind that the get_sub_field() function only works within the have_rows() function. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/get_sub_field/.

    Thanks 🙂

  • Hi James, thank you for your reply.
    Below the export of the group. It is a long list because of all the countries.

    if( function_exists('acf_add_local_field_group') ):
    
    acf_add_local_field_group(array (
    	'key' => 'group_5852da32422bb',
    	'title' => 'v4 Land en visa keuze versie (kopie)',
    	'fields' => array (
    		array (
    			'key' => 'field_5852da3251980',
    			'label' => 'Veldkeuze visa',
    			'name' => 'veldkeuze_visa',
    			'type' => 'repeater',
    			'instructions' => '',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'collapsed' => 'field_585141db9d6dd',
    			'min' => '',
    			'max' => '',
    			'layout' => 'block',
    			'button_label' => 'Land toevoegen',
    			'sub_fields' => array (
    				array (
    					'key' => 'field_5852da32598f9',
    					'label' => 'Land keuze',
    					'name' => 'land_keuze',
    					'type' => 'select',
    					'instructions' => '',
    					'required' => 1,
    					'conditional_logic' => 0,
    					'wrapper' => array (
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'choices' => array (
    						'Afghanistan' => 'Afghanistan',
    						'Albanië' => 'Albanië',
    						'Algerije' => 'Algerije',
    						'Andorra' => 'Andorra',
    						'Angola' => 'Angola',
    						'Antigua en Barbuda' => 'Antigua en Barbuda',
    						'Argentinië' => 'Argentinië',
    						'Armenië' => 'Armenië',
    						'Australië' => 'Australië',
    						'Azerbeidzjan' => 'Azerbeidzjan',
    						'Bahama\'s' => 'Bahama\'s',
    						'Bahrein' => 'Bahrein',
    						'Bangladesh' => 'Bangladesh',
    						'Barbados' => 'Barbados',
    						'België' => 'België',
    						'Belize' => 'Belize',
    						'Benin' => 'Benin',
    						'Bhutan' => 'Bhutan',
    						'Bolivia' => 'Bolivia',
    						'Bosnië en Herzegovina' => 'Bosnië en Herzegovina',
    						'Botswana' => 'Botswana',
    						'Brazilië' => 'Brazilië',
    						'Brunei' => 'Brunei',
    						'Bulgarije' => 'Bulgarije',
    						'Burkina Faso' => 'Burkina Faso',
    						'Burundi' => 'Burundi',
    						'Cambodja' => 'Cambodja',
    						'Canada' => 'Canada',
    						'Centraal-Afrikaanse Republiek' => 'Centraal-Afrikaanse Republiek',
    						'Chili' => 'Chili',
    						'China' => 'China',
    						'Colombia' => 'Colombia',
    						'Comoren' => 'Comoren',
    						'Congo-Brazzaville' => 'Congo-Brazzaville',
    						'Congo-Kinshasa' => 'Congo-Kinshasa',
    						'Costa Rica' => 'Costa Rica',
    						'Cuba' => 'Cuba',
    						'Cyprus' => 'Cyprus',
    						'Denemarken' => 'Denemarken',
    						'Djibouti' => 'Djibouti',
    						'Dominica' => 'Dominica',
    						'Dominicaanse Republiek' => 'Dominicaanse Republiek',
    						'Duitsland' => 'Duitsland',
    						'Ecuador' => 'Ecuador',
    						'Egypte' => 'Egypte',
    						'El Salvador' => 'El Salvador',
    						'Equatoriaal-Guinea' => 'Equatoriaal-Guinea',
    						'Eritrea' => 'Eritrea',
    						'Estland' => 'Estland',
    						'Ethiopië' => 'Ethiopië',
    						'Fiji' => 'Fiji',
    						'Filipijnen' => 'Filipijnen',
    						'Finland' => 'Finland',
    						'Frankrijk' => 'Frankrijk',
    						'Gabon' => 'Gabon',
    						'Gambia' => 'Gambia',
    						'Georgië' => 'Georgië',
    						'Ghana' => 'Ghana',
    						'Grenada' => 'Grenada',
    						'Griekenland' => 'Griekenland',
    						'Guatemala' => 'Guatemala',
    						'Guinee' => 'Guinee',
    						'Guinee-Bissau' => 'Guinee-Bissau',
    						'Guyana' => 'Guyana',
    						'Haïti' => 'Haïti',
    						'Honduras' => 'Honduras',
    						'Hongarije' => 'Hongarije',
    						'Ierland' => 'Ierland',
    						'IJsland' => 'IJsland',
    						'India' => 'India',
    						'Indonesië' => 'Indonesië',
    						'Irak' => 'Irak',
    						'Iran' => 'Iran',
    						'Israël' => 'Israël',
    						'Italië' => 'Italië',
    						'Ivoorkust[10]' => 'Ivoorkust[10]',
    						'Jamaica' => 'Jamaica',
    						'Japan' => 'Japan',
    						'Jemen' => 'Jemen',
    						'Jordanië' => 'Jordanië',
    						'Kaapverdië' => 'Kaapverdië',
    						'Kameroen' => 'Kameroen',
    						'Kazachstan' => 'Kazachstan',
    						'Kenia' => 'Kenia',
    						'Kirgizië' => 'Kirgizië',
    						'Kiribati' => 'Kiribati',
    						'Koeweit' => 'Koeweit',
    						'Kroatië' => 'Kroatië',
    						'Laos' => 'Laos',
    						'Lesotho' => 'Lesotho',
    						'Letland' => 'Letland',
    						'Libanon' => 'Libanon',
    						'Liberia' => 'Liberia',
    						'Libië' => 'Libië',
    						'Liechtenstein' => 'Liechtenstein',
    						'Litouwen' => 'Litouwen',
    						'Luxemburg' => 'Luxemburg',
    						'Macedonië[11]' => 'Macedonië[11]',
    						'Madagaskar' => 'Madagaskar',
    						'Malawi' => 'Malawi',
    						'Maldiven' => 'Maldiven',
    						'Maleisië' => 'Maleisië',
    						'Mali' => 'Mali',
    						'Malta' => 'Malta',
    						'Marokko' => 'Marokko',
    						'Marshalleilanden' => 'Marshalleilanden',
    						'Mauritanië' => 'Mauritanië',
    						'Mauritius' => 'Mauritius',
    						'Mexico' => 'Mexico',
    						'Micronesia' => 'Micronesia',
    						'Moldavië' => 'Moldavië',
    						'Monaco' => 'Monaco',
    						'Mongolië' => 'Mongolië',
    						'Montenegro' => 'Montenegro',
    						'Mozambique' => 'Mozambique',
    						'Myanmar' => 'Myanmar',
    						'Namibië' => 'Namibië',
    						'Nauru' => 'Nauru',
    						'Nederland' => 'Nederland',
    						'Nepal' => 'Nepal',
    						'Nicaragua' => 'Nicaragua',
    						'Nieuw-Zeeland' => 'Nieuw-Zeeland',
    						'Niger' => 'Niger',
    						'Nigeria' => 'Nigeria',
    						'Noord-Korea' => 'Noord-Korea',
    						'Noorwegen' => 'Noorwegen',
    						'Oeganda' => 'Oeganda',
    						'Oekraïne' => 'Oekraïne',
    						'Oezbekistan' => 'Oezbekistan',
    						'Oman' => 'Oman',
    						'Oostenrijk' => 'Oostenrijk',
    						'Oost-Timor' => 'Oost-Timor',
    						'Pakistan' => 'Pakistan',
    						'Palau' => 'Palau',
    						'Palestina' => 'Palestina',
    						'Panama' => 'Panama',
    						'Papoea-Nieuw-Guinea' => 'Papoea-Nieuw-Guinea',
    						'Paraguay' => 'Paraguay',
    						'Peru' => 'Peru',
    						'Polen' => 'Polen',
    						'Portugal' => 'Portugal',
    						'Qatar' => 'Qatar',
    						'Roemenië' => 'Roemenië',
    						'Rusland' => 'Rusland',
    						'Rwanda' => 'Rwanda',
    						'Saint Kitts en Nevis' => 'Saint Kitts en Nevis',
    						'Saint Lucia' => 'Saint Lucia',
    						'Saint Vincent en de Grenadines' => 'Saint Vincent en de Grenadines',
    						'Salomonseilanden' => 'Salomonseilanden',
    						'Samoa' => 'Samoa',
    						'San Marino' => 'San Marino',
    						'Sao Tomé en Principe' => 'Sao Tomé en Principe',
    						'Saoedi-Arabië' => 'Saoedi-Arabië',
    						'Senegal' => 'Senegal',
    						'Servië' => 'Servië',
    						'Seychellen' => 'Seychellen',
    						'Sierra Leone' => 'Sierra Leone',
    						'Singapore' => 'Singapore',
    						'Slovenië' => 'Slovenië',
    						'Slowakije' => 'Slowakije',
    						'Soedan' => 'Soedan',
    						'Somalië' => 'Somalië',
    						'Spanje' => 'Spanje',
    						'Sri Lanka' => 'Sri Lanka',
    						'Suriname' => 'Suriname',
    						'Swaziland' => 'Swaziland',
    						'Syrië' => 'Syrië',
    						'Tadzjikistan' => 'Tadzjikistan',
    						'Tanzania' => 'Tanzania',
    						'Thailand' => 'Thailand',
    						'Togo' => 'Togo',
    						'Tonga' => 'Tonga',
    						'Trinidad en Tobago' => 'Trinidad en Tobago',
    						'Tsjaad' => 'Tsjaad',
    						'Tsjechië' => 'Tsjechië',
    						'Tunesië' => 'Tunesië',
    						'Turkije' => 'Turkije',
    						'Turkmenistan' => 'Turkmenistan',
    						'Tuvalu' => 'Tuvalu',
    						'Uruguay' => 'Uruguay',
    						'Vanuatu' => 'Vanuatu',
    						'Vaticaanstad' => 'Vaticaanstad',
    						'Venezuela' => 'Venezuela',
    						'Verenigd Koninkrijk' => 'Verenigd Koninkrijk',
    						'Verenigde Arabische Emiraten' => 'Verenigde Arabische Emiraten',
    						'Verenigde Staten' => 'Verenigde Staten',
    						'Vietnam' => 'Vietnam',
    						'Wit-Rusland' => 'Wit-Rusland',
    						'Zambia' => 'Zambia',
    						'Zimbabwe' => 'Zimbabwe',
    						'Zuid-Afrika' => 'Zuid-Afrika',
    						'Zuid-Korea' => 'Zuid-Korea',
    						'Zuid-Soedan' => 'Zuid-Soedan',
    						'Zweden' => 'Zweden',
    						'Zwitserland' => 'Zwitserland',
    					),
    					'default_value' => array (
    					),
    					'allow_null' => 0,
    					'multiple' => 0,
    					'ui' => 0,
    					'ajax' => 0,
    					'return_format' => 'array',
    					'placeholder' => '',
    				),
    				array (
    					'key' => 'field_5852da3259a2c',
    					'label' => 'Visa soort',
    					'name' => 'visa_soort',
    					'type' => 'repeater',
    					'instructions' => '',
    					'required' => 0,
    					'conditional_logic' => 0,
    					'wrapper' => array (
    						'width' => '',
    						'class' => '',
    						'id' => '',
    					),
    					'collapsed' => 'field_585141db9d80b',
    					'min' => '',
    					'max' => '',
    					'layout' => 'row',
    					'button_label' => 'Nieuw visum toevoegen',
    					'sub_fields' => array (
    						array (
    							'key' => 'field_5852da326c755',
    							'label' => 'Visa soort',
    							'name' => 'visa_soort',
    							'type' => 'select',
    							'instructions' => 'Kies een type visum.',
    							'required' => 1,
    							'conditional_logic' => 0,
    							'wrapper' => array (
    								'width' => '',
    								'class' => '',
    								'id' => '',
    							),
    							'choices' => array (
    								'Toeristenvisum' => 'Toeristenvisum',
    								'Zakenvisum' => 'Zakenvisum',
    								'Backpacken visum' => 'Backpacken visum',
    								'Visum I-P-B' => 'Visum I-P-B',
    								'Studentenvisum' => 'Studentenvisum',
    							),
    							'default_value' => array (
    								0 => 'Toeristenvisum',
    								1 => 'Zakenvisum',
    								2 => 'Backpacken visum',
    								3 => 'Visum I-P-B',
    								4 => 'Studentenvisum',
    							),
    							'allow_null' => 0,
    							'multiple' => 0,
    							'ui' => 0,
    							'ajax' => 0,
    							'return_format' => 'array',
    							'placeholder' => '',
    						),
    						array (
    							'key' => 'field_5852da326c8a8',
    							'label' => 'Dataweergave',
    							'name' => 'dataweergave',
    							'type' => 'repeater',
    							'instructions' => '',
    							'required' => 0,
    							'conditional_logic' => 0,
    							'wrapper' => array (
    								'width' => '',
    								'class' => '',
    								'id' => '',
    							),
    							'collapsed' => '',
    							'min' => '',
    							'max' => '',
    							'layout' => 'row',
    							'button_label' => 'Voeg data in',
    							'sub_fields' => array (
    								array (
    									'key' => 'field_5852da327dcf4',
    									'label' => 'Punten',
    									'name' => 'punten',
    									'type' => 'taxonomy',
    									'instructions' => '',
    									'required' => 1,
    									'conditional_logic' => 0,
    									'wrapper' => array (
    										'width' => '',
    										'class' => '',
    										'id' => '',
    									),
    									'taxonomy' => 'regel_ranges',
    									'field_type' => 'checkbox',
    									'allow_null' => 0,
    									'add_term' => 1,
    									'save_terms' => 1,
    									'load_terms' => 1,
    									'return_format' => 'object',
    									'multiple' => 0,
    								),
    								array (
    									'key' => 'field_5852da327de52',
    									'label' => 'Kosten',
    									'name' => 'kosten',
    									'type' => 'taxonomy',
    									'instructions' => '',
    									'required' => 1,
    									'conditional_logic' => 0,
    									'wrapper' => array (
    										'width' => '',
    										'class' => '',
    										'id' => '',
    									),
    									'taxonomy' => 'tarieven',
    									'field_type' => 'checkbox',
    									'allow_null' => 0,
    									'add_term' => 0,
    									'save_terms' => 1,
    									'load_terms' => 1,
    									'return_format' => 'object',
    									'multiple' => 0,
    								),
    							),
    						),
    					),
    				),
    			),
    		),
    	),
    	'location' => array (
    		array (
    			array (
    				'param' => 'post_type',
    				'operator' => '==',
    				'value' => 'nationaliteit',
    			),
    		),
    	),
    	'menu_order' => 0,
    	'position' => 'acf_after_title',
    	'style' => 'default',
    	'label_placement' => 'top',
    	'instruction_placement' => 'label',
    	'hide_on_screen' => '',
    	'active' => 1,
    	'description' => '',
    ));
    
    endif;

    I just need to know if i can add multiple records to one post. And output just one value in my template. I hope it is more clear now.

    Thank you

  • Hi @redcat

    If you want to query a certain post based on the repeater field value, kindly check this page: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/.

    But I suggest you set the country as a taxonomy or a new custom field outside of the repeater instead and create posts for each Nationality and Country combination. So each post will only have 20 rows of the repeater and it will be easier to query the data.

    I hope this makes sense 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Multiple nested fields in one post, don't want to display all data’ is closed to new replies.