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)

You must be logged in to reply to this topic.