Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting posts from WordPress in my android app

I am new in Android development and I am trying to make an app that will simply display the post categories and posts from a WordPress website. Can any one help me, please.

like image 683
Arun Avatar asked Jan 20 '14 10:01

Arun


People also ask

Can you use WordPress on Android?

In one word: yes. WordPress's mobile apps for Android and iPhone allows users to create posts, upload photos, moderate comments and more.

How do I get a WordPress post API?

To use the WordPress REST API, simply add /wp-json/wp/v2/posts to the end of your WordPress site URL. This will give you a list of posts (in JSON format). The default number of posts returned is 10, but you can choose to show more or less with the per_page argument — we'll talk about that below.


1 Answers

I think this is better, for using wordpress rest api you need to use Wordpress 4.7 or higher, or install the Rest Api plugin in previous versions. Then you need to configure Permalinks in wordpress, this will make rest api endpoints to work.

For reduce the size and customice the output json you may install the Rest api filter fields plugin see the bellow example:

Fetching Specified Number of Post

For fetching specified number of posts you can use post-per-page filter. The below URL will fetch only 3 posts. http://your-blog-url/wp-json/wp/v2/posts?filter[posts_per_page]=3

Fetching Particular Post

You can fetch any particular post by its id. http://your-blog-url/wp-json/wp/v2/posts/67

Here 67 is the id of the post.

Filtering Fields

As you have seen in above JSON data that there are several fields that we don’t require. So with the help of REST API – Filter Fields plugin you can filter few fields. For example you want to fetch only post’s id and title then it can be done by using following URL. http://your-blog-url/wp-json/wp/v2/posts?fields=id,title

like image 60
Lorenzo Lopez Avatar answered Oct 02 '22 23:10

Lorenzo Lopez