Monday, January 16, 2023
HomeWordPress DevelopmentDeadly error in customized finish level in WP-JSON

Deadly error in customized finish level in WP-JSON


The error log

Deadly error: Uncaught Error: Name to a member perform has_param() on null in /dwelling/km/public_html/wp-includes/rest-api/endpoints/class-wp-rest-controller.php:591 Stack hint: 
#0 /dwelling/km/public_html/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(1751): WP_REST_Controller->get_fields_for_response(NULL) 
#1 /dwelling/km/public_html/wp-content/themes/apptheme-child/capabilities.php(107): WP_REST_Posts_Controller->prepare_item_for_response(Object(WP_Post), NULL)
#2 /dwelling/km/public_html/wp-includes/rest-api/class-wp-rest-server.php(1171): get_app_data(Object(WP_REST_Request)) 
#3 /dwelling/km/public_html/wp-includes/rest-api/class-wp-rest-server.php(1018): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/app_data/v1/da...', Array, NULL) 
#4 /dwelling/km/public_html/wp-includes/rest-api/class-wp-rest-server.php(442): WP_REST_Server->dispatch(Object(WP_REST_Request)) 
#5 /dwelling/km/public_html/wp-includes/rest-api.php(410): WP_REST_Server->serve_request('/app_data/v1/da...') 
#6 /dwelling/km/public_html/wp-includes/class-wp-hook.php(308): rest_api_loaded(Object(WP)) 
#7 /dwelling/km/public_html/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters('', Array) 
#8 /dwelling/km/public_html/wp-includes/plugin.php(565): WP_Hook->do_action(Array) 
#9 /dwelling/km/public_html/wp-includes/class-wp.php(399): do_action_ref_array('parse_request', Array) 
#10 /dwelling/km/public_html/wp-includes/class-wp.php(780): WP->parse_request('') 
#11 /dwelling/km/public_html/wp-includes/capabilities.php(1332): WP->fundamental('') 
#12 /dwelling/km/public_html/wp-blog-header.php(16): wp() 
#13 /dwelling/km/public_html/index.php(17): require('/dwelling/km...') 
#14 {fundamental} thrown in /dwelling/km/public_html/wp-includes/rest-api/endpoints/class-wp-rest-controller.php on line 591

The code on capabilities.php(107)

$a_posts_args = array(
    'posts_per_page' => -1,
    'post_type' => 'adverts',
    'post_status' => 'publish'
);

$a_posts = get_posts($a_posts_args);
//print_r($a_posts);

$controller2 = new WP_REST_Posts_Controller('publish');

$array2 = array();
foreach ( $a_posts as $publish ) {
    $data2 = $controller2->prepare_item_for_response($publish,$request); // That is line 107
    $array2[] = $controller2->prepare_response_for_collection($data2);
}
wp_reset_query();

The code was working tremendous and I simply acquired this error like two days in the past. I’ve not added any new plugins. I additionally checked the ‘show_in_rest’ for this practice publish kind and it’s set to TRUE.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments