• I am trying to add option “show_on_front” into REST API. Following code works for other object types “post”|”page” etc. but not for “setting”. Is there something I am missing?

    
    function add_field_show_on_front()
    {
    	$args = [
    		'get_callback' => function() {
    			return get_option('show_on_front');
    		}
    	];
    
    	register_rest_field('setting', 'show_on_front', $args);
    }
    
    add_filter('rest_api_init', 'add_field_show_on_front');
    
    • This topic was modified 5 years, 1 month ago by vavra7.
Viewing 2 replies - 1 through 2 (of 2 total)
  • $args = [
    		'get_callback' => function() {
    			return get_option('show_on_front');
    		}
    	];
    // conversion ObjectClousure to native value
    $args['get_callback']();

    I think args is an array.

    Thread Starter vavra7

    (@vavra7)

    Yes, args is an array. I have args of type array and args are correct. As I wrote in description. The code works for object types “post”|”page” etc. but not for “setting”.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘It is not possible to register field for settings route in REST API’ is closed to new replies.