You can create a route for Rest API using the below code. Simply put this code in your function.php file
/* Route For api */
add_action( 'rest_api_init', function () {
register_rest_route('wp/v2', 'test', array(
'methods' => array('GET', 'POST'),
'callback' => 'test',
));
} );
And then simply create a callback function test and put your stuff in to that function
function test(){
// put your stuff here
}
Related Posts:
- search blog posts by author first name and or last name
- Optimal WP Web App Backend for mobile app development
- Adding additional data to WP_Post object
- WP_Query: Why is sticky post not first item in loop?
- WP Rest API v2 filter and display latest post with specific tag
- How do I reorder (pop and push) items from WP_Query?
- How to exclude latest x posts from a paginated query?
- Reverse chronology of post listing
- WP_Query to work with custom view
- Most viewed post for the last 2 days using WP_Query
- Adding Post Counts to Menu (Nav) Programmatically?
- This AJAX Code Doesn’t Work – Looking for elegant solution
- How to add posts to wp_query result?
- Posts for next month
- WP_Query only ONE post, won’t work
- Unable to modify(update) posts – Page not found
- Hide Post comments when displayed via WP_Query
- Hiding posts in a list from specified categories
- Group posts by year in loop
- wp query with dynamic taxonomies and terms?
- How to get posts by multiple post slugs? [duplicate]
- Blogroll – Different layout for first post
- WP_Query do not load specifed number of post
- How do I use `posts_distinct` correctly?
- How can I remove posts of a certain category from homepage after a specified time period?
- Automatic value for custom fields for posts
- Loop through all product posts?
- How to find what index page a post is on?
- Display post from current category and same tag?
- WordPress REST API not returning all posts
- Get Posts that are in the current month or later
- WP Query to Get Array of Slugs
- How can I sort posts by the date and a custom meta field?
- Exclude post_meta from Rest API Endpoint
- Hiding Draft Post In Admin
- How can I get the media inside a post?
- How to verify wp user password by sql query in wp? [closed]
- Lost draft under all posts and drafts
- Get user categories with most posts in it
- Query posts and return XML
- Query Posts With Over 1000 Views
- List authors with the last post title and order by last post date
- How to order posts by meta_value and title
- WordPress query_posts by tag doesn’t work anymore(?)
- Ignore latest two posts
- Show posts by author of membership level (Paid Membership Pro)
- Print out last 3 blogposts
- Why posts array is empty?
- How to group only VISIBLE posts? [closed]
- How to check in functions.php if there is data in a WP_Query?
- Shortcode with ‘year’ parameter
- Creating a WordPress Post via REST API – HTML or Markdown?
- On what hook can I get the queried object’s final state?
- How can I insert a new markup element after 4 posts automatically? [closed]
- If no posts exist for current day and month, show the next available day of posts
- how to handle the loop using filling bootstrap grid structure?
- wp_query if have posts show date but not in loop
- Query function not executed between element [closed]
- Creating a related posts section in wordpress inside a default post
- How to display WP Query filters?
- Finding a post’s slug
- Is there a function to get post info for any publish_status by post ID?
- How Can I Always Display A Particular Post First Using WP_Query?
- How do I display main query posts in random order using add_filter
- Why sorting posts doesn’t work properly?
- the wp_post_update isn’t working all the time
- WordPress rest API get Posts parent by post ID
- Updating post status via rest api
- How to set the post permalink using the WordPress REST API?
- query posts with selected post ids first
- Change URL of previous posts and next posts link in WordPress
- How to invoke a HTML custom button based on a HTML dropdownlist menu
- How to prevent post update using transition_post_status
- Order posts inside bootstrap card columns
- long-title posts do not want published
- Mix post date with post meta value using WP_Query
- How to get value of a selected option from select tag and use it in WP_query to filter posts?
- Counting Posts by Category
- show image gallery in archives or category page
- Page with Category Returning 1
- The first post appears twice
- wp_query args with relation
- WP_Query sort by meta_value_num or date
- Get 5 most recent categories
- Creating Ordered Query using Meta_key
- WP Query between posts custom fields [duplicate]
- Why I obtain this WP_Query strange behavior trying to select posts having a specific tag?
- Retrieve latest post by multiple categories with ID
- Update Post with Modified Data
- Can’t get pagination to work
- How to Include a common category in a custom Category Search
- wp_query select if have comments
- wp_query posts sorting doesn’t work
- Order by ‘s’ using WP_Query()
- custom sort posts in archive/taxanomy page
- Trying to create shortcode listing custom posts, but formating not being included
- Show Title/Date/Excerpt of first post & only Title for rest in Query [duplicate]
- Get posts after calculating meta key
- How edit footer copyright info? [closed]
- date_query returning only the most recent post instead of the post published before today