Support » Plugin: WP REST API (WP API) » Extending WP_JSON_CustomPostType gives

  • Resolved Compute


    Error message:
    Catchable fatal error: Argument 1 passed to WP_JSON_CustomPostType::__construct() must implement interface WP_JSON_ResponseHandler, none given, called in /var/www/wp-content/plugins/... on line 12 and defined in /var/www/wp-content/plugins/json-rest-api/lib/class-wp-json-customposttype.php on line 31


    function osd_api() {
    	global $osd_api;
    	$osd_api = new OSD_API();
    	add_filter( 'json_endpoints', array( $osd_api, 'register_routes' ) );
    add_action( 'plugins_loaded', 'osd_api' );
    class OSD_API extends WP_JSON_CustomPostType {
    	protected $base = '/swimmers';
    	protected $type = 'swimmer';
    	function register_routes( $routes ) {
    		$routes = parent::registerRoutes( $routes );
    		return $routes;

    I’ve tryed to follow your guide here but it also gives me the error message even if I change my code to the example code (the second one).

Viewing 1 replies (of 1 total)
  • After having a deep look into the code I realized that I should change the hook:
    add_action( 'wp_json_server_before_serve', 'osd_api' );

Viewing 1 replies (of 1 total)
  • The topic ‘Extending WP_JSON_CustomPostType gives’ is closed to new replies.