Custom theme options display specific section and saving problem

Question

I have a custom theme options page with multiple sections and fields. What I cannot figure out is how to display specific sections at specific places and in addition if there are 2 or more sections per page present then settings do not seem to getting saved. I have seen others solving this problem by grouping the settings register_setting() by providing the same $option_group however this does not make sense to me – does not seem logical nor neat. On the other hand I do not wish to edit core WordPress files/templates not meant to be altered (since there are no filters etc for that purpose). Another way is to use tabs but doing so does not serve my purpose – I have a custom panel with tabs using javascript to alter visibility according to my needs. From my understanding do_settings_sections displays all fields associated with a specific page right in the place where this function is present and I do not know how to bypass this function.

EDIT: I needed to use do_settings_fields instead of do_settings_sections. A really newbie mistake. However the saving problem remains.

If I have only one section like below, everything works fine no matter if I have one settings field or more.

settings_fields( 'my_section' );
do_settings_fields( 'my_options_group', 'my_section' );

For the code below, only the last one saves, why would that be?

settings_fields( 'my_section' );
do_settings_fields( 'my_options_group', 'my_section' );
settings_fields( 'my_section_a' );
do_settings_fields( 'my_options_group_a', 'my_section_a' );

EDIT 2: As I can see, WordPress is generating nonce input only for the last field in the page.

<input type="hidden" name="action" value="update">
<input type="hidden" id="_wpnonce" name="_wpnonce" value="902547fd82">
0
, Arg Geo 3 years 2020-04-05T04:50:50-05:00 0 Answers 80 views 0

Leave an answer

Browse
Browse