1

This seems like it should be very simple to achieve, but I have spent far too long trying to figure it out. I have two settings sections:

add_settings_section( 'cp_required_info', 'One', array($this, 'cp_required_info'), 'cp-settings' );
add_settings_section( 'cp_sync_info', 'Two', array($this, 'cp_sync_info'), 'cp-settings' );
register_setting( 'cp-settings', 'cp_admin_options', array( $this, 'sanitize' ) );

How can I get these sections to output in different locations in the HTML? do_settings_sections is only allowing $page. I have tried do_settings_fields which allows for $page and $section and it does achieve what I want, however when I remove the do_settings_section and leave only the do_settings_fields, all of my output disappears. Below is an example of what I am trying to achieve.

<?php settings_fields( 'cp-settings' );   
//do_settings_sections( 'cp-settings' );
do_settings_fields( 'cp-settings', 'cp_required_info' );?>

<!--Some HTML goes here-->

<?php
do_settings_fields( 'cp-settings', 'cp_sync_info' );?>
?>

Does anyone know how to achieve this? All of my callbacks are functioning properly, its just a matter of placing the sections on the page.

EDIT: Including the add_settings_fields:

public function cp_required_info() {
        add_settings_field( 'cp_apikey', 'API Key:', array( $this, 'cp_apikey_callback' ), 'cp-settings', 'cp_required_info', array( 'label_for' => 'cp_apikey') );      
        add_settings_field( 'cp_username', 'Username:', array( $this, 'cp_username_callback' ), 'cp-settings', 'cp_required_info', array( 'label_for' => 'cp_username') );      
        add_settings_field( 'cp_tablename', 'Table Name:', array( $this, 'cp_tablename_callback' ), 'cp-settings', 'cp_required_info', array( 'label_for' => 'cp_tablename') );      
    }

public function cp_sync_info() {
        add_settings_field('cp_collect_posts', 'Posts', array($this, 'cp_posts_callback'), 'cp-settings', 'cp_sync_info', array( 'label_for' => 'cp_collect_posts') );
    }
1

Nevermind, figured it out. Made the following changes:

add_settings_section( 'cp_required_info', null, array($this, 'cp_required_info'), 'cp-settings-group' );
add_settings_section( 'cp_sync_info', null, array($this, 'cp_sync_info'), 'cp-settings-group' );
register_setting( 'cp-settings-group', 'cp_admin_options', array( $this, 'sanitize' ) );

<?php settings_fields( 'cp-settings-group' );   
do_settings_sections( 'cp-settings-group' );
do_settings_fields( 'cp-settings', 'cp_required_info' );?>

<!--Some HTML goes here-->

<?php
do_settings_fields( 'cp-settings', 'cp_sync_info' );?>
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.