PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 30, 2022

[FIXED] I'm trying to add custom route in wordpress

 January 30, 2022     php, wordpress, wordpress-rest-api     No comments   

Issue

I'm trying to add custom route in WordPress but it return "No route was found matching the URL and request method."

Here is my code add_action('rest_api_init', 'university_search_route');

function university_search_route()
{
  register_rest_route('university/v1', 'search', array(
    'methods' => 'WP_REST_SERVER::READABLE',
    'callback' => 'universitySearchResults',
  ));
}

function universitySearchResults()
{
  return 'Hello';
}

What I'm doing wrong here ?


Solution

function university_search_route()
{
  register_rest_route('university/v1', 'search', array(
    'methods' => 'WP_REST_Server::READABLE', //probs the uppercase you had
    'callback' => 'universitySearchResults',
  ));
}

function universitySearchResults()
{
  return 'Hello';
}


Answered By - Stevo
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing