Settings API – adding setting fields dynamically?

It sounds like you would need a way to get those dynamic fields into the my_options function each time it’s called. You could try creating your own filter to use:

function my_options() {
    $myarray = apply_filters( 'my_get_options_dynamically', array() );
    $count   = 0;

    foreach($myarray as $something) {
        $count++;
        $options[] = array(
            'id'         => 'something'. $count,
            'title'      => $something['title'],
            'type'       => 'type',
            'desription' => $something['description'],
        );

        return $options;
}

add_filter( 'my_get_options_dynamically', function() {
    // Some code to get the dynamic option array.
    return array( array(
        'title'       => 'Some option title',
        'description' => 'Some option description',
    ) );
} );

Leave a Comment