Search
 
SCRIPT & CODE EXAMPLE
 

PHP

rest api response 404 wordpress

// if there is no posts return 404 with custom message
if( empty($query->posts) ){
	return new WP_Error( 'no_posts', __('No post found'), array( 'status' => 404 ) ); // status can be changed to any number
}

// output
{
	"code": "no_posts",
	"message": "No post found",
	"data": {
		"status": 404
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: laravel create session table 
Php :: laravel validation types 
Php :: text box should accept only alphanumeric not special characters in php 
Php :: change default user table name laravel 
Php :: switch php version ubuntu 20.04 
Php :: symfony messenger config 
Php :: tinker faker 
Php :: wp php get rows number from mysql 
Php :: laravel passport client 
Php :: laravel model uploaded file name 
Php :: laravel blade php variable concatenate javascript variable 
Php :: get git branch by php 
Php :: contact form 7 remove br 
Php :: how to save data from api to laravel 
Php :: php find multiple value in array 
Php :: laravel form validation based on another field value 
Php :: php get variable by string name 
Php :: php xml to json 
Php :: php rearrange array 
Php :: get number of days between two dates php 
Php :: how to create constant in php 
Php :: laravel 8 carbon if date is today 
Php :: laravel carbon date format 
Php :: The specified module could not be found php 
Php :: display all files in a directory php 
Php :: how to fetch the sum of column in php mysql 
Php :: php dirname 
Php :: laravel array search blade 
Php :: Using the PHPExcel library to read an Excel file and transfer the data into a database 
Php :: removing the last value of an array 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =