Nowadays WordPress is the one of the popular Content management system for developed any website.Simultaneously mobile application also increased after launched of smartphones android,iPhone,windows and much more. So Now you are also looking for launch your application of your website.
As we all know that for get data in application we need WEB-API so using api we can fetch all data from website and display in our application.So here is the solution for how to developed mobile application for WordPress website using JSON-API.
JSON API allows you to retrieve and manipulate WordPress content using HTTP requests. There are three main goals:
- Provide a simple, consistent external interface
- Create a stable, understandable internal implementation
- Enable new types of extensions for WordPress
JSON-API is one of the most useful plugin used for generate web-api for wordpress website.using Json-api you are easily get all content from website like post,category,latest post,category index much more.Also use for create,update and delete post.
Json api general concept is request,response and controller.
So if you have already wordpress website then install JSON-API plugin and get access for WEB-API.
Now let start with some of the basic required method that used for get data or insert data in application and web.After install plugin activate it.In setting–>JSON-API you will find below screen.
Now Click on core links for get details
Get Recent Post
If you want recent post then just click on get_recent_posts you will get recent post.you can also specified number of count you want.For example if you want display only 5 latest post then at the end add count like below.
http://yourdomainname.com/?json=get_recent_posts&count=5
Get All Posts
If you want to display all posts in your application then just click on get_posts you will get all posts.
http://yourdomainname.com/?json=get_posts
Get Particular post
Now if you want to display Particular post or page then use get_post & get_page.here you have to define your post id or post slug like below.
http://yourdomainname.com/?json=get_post&id=1 http://yourdomainname.com/?json=get_post&slug=hello-world
Get Category Based Posts
Now if you are looking for display post based on category they use get_category_posts here also you have to define either id or slug of category.
http://yourdomainname.com/?json=get_category_posts&slug=test
Same like above you can fetch post based on different conditions Eg. date,tag,author much more.
Now click on Posts For Add,update and delete data from application.
Create Post
If you click on create_post it gives you an error message as below.Same message display for update and delete also.
{ "status": "error", "error": "You must include a 'nonce' value to create posts. Use the `get_nonce` Core API method." }
Now you think why its display this message? why its not working as simple get(core) methods?
Here is the answer of your all questions.
Ans. Just for security its ask for nonce generation because after add nonce on your json request, it will allow you to create,update and delete data.So below i will explain how to create nonce for all operation.
To generate nonce for insert
http://yourdomainname.com/?json=get_nonce&controller=posts&method=create_post
it will return below result
{ "status": "ok", "controller": "posts", "method": "create_post", "nonce": "16096ff518" }
Copy the nonce in notepad or any file because this nonce is used every-time when you create new post using application.So whenever user want to create post we have to send nonce as request.
Same like you have to generate nonce for update and delete same as below.
To generate nonce for update http://yourdomainname.com/?json=get_nonce&controller=posts&method=update_post To generate nonce for delete http://localhost/wordpress-json/?json=get_nonce&controller=posts&method=delete_post
Now how to create,update and delete post using data request are below.
To Create post add nonce when we pass the data.
http://yourdomainname.com/?json=posts/create_post&nonce=b9224c227b&title=YOURTITLE&content=YOURCONTENT&status=publish
To Update a post
http://yourdomainname.com/?json=posts/update_post&id=23&title=UPDATETITLE&nonce=cfb0c0519d
To Delete a post
http://yourdomainname.com/?json=posts/delete_post&id=23&nonce=1dcbd38ca1
To update custom field in a post/custom_post_type with custom fields
http://yourdomainname.com/?json=posts/update_post&id=29&title=post&nonce=cfb0c0519d&post_type=property&custom[wpcf-lines]=222
I hope this tutorial is helpful for you.more details on json api click here
If you are looking for mobile application developer using your wordpress website then Contact us. We Will Provide you Best solution for mobile application in android,iPhone,Blackberry and windows.
The post Looking for developed mobile application for wordpress website? appeared first on Excellent Web World.