How to get WordPress post category name, author name and tags name


#1

Hi everyone, I am new in ionic, I am making an app with WordPress. I have used rest api plugin, {{item.category}} {{item.tags}} {{item.author}} showing id name, but I want to show name. Can you please help me.


#2

{{item.name}} no problem


#3

@FnnHuman Thank you for your reply but its not working


#4

how is that? i am sure it should work


#5

@FnnHuman Here is wp-json/wp/v2/posts response Screenshot_2

Here is my code

<ion-content padding>
  <ion-list>
    <button ion-item *ngFor="let item of items" (click)="itemTapped($event, item)">
    <ion-avatar item-left> <img *ngIf="item.featured_image_urls && item.featured_image_urls.thumbnail" [src]="item.featured_image_urls.thumbnail"> </ion-avatar>
    <h2 [innerHTML]="item.title.rendered"></h2>
    <p>{{item.date | date:'MMM dd, yyyy'}}</p>
    <p>{{item.category}}</p>
    <p>{{item.tags}}</p>
    <p [innerHTML]="item.excerpt.rendered"></p>
    </button>
  </ion-list>
</ion-content>

#6

I don’t see a response. I see a virtually useless image.


#7

@rapropos Yes, I gave screenshot only response is same as your are seeing in screenshot


#8

No it isn’t. The response is JSON, which should be posted as text, not an image.


#9

@rapropos I meant to say API response


#10

I think this is a wordpress problem.

If your first request only returns th ids you have to make some more requests to get more information.

For user infos for example

http://demo.wp-api.org/wp-json/wp/v2/users/

Or perhaps you could change the first request to get the infos that you want.

Or you make a server side proxy api that gather the infos that you want from wordpress api and deliver one json objekt to your ionic app.


#11

@Jacktoolsnet Thank you for your reply, Can you please tell me how to change response http://demo.wp-api.org/wp-json/wp/v2/posts/ same type response I am getting from my WordPress, I am new in ionic I don’t have much more knowledge.


#12

If I get the wp doc right you only get the id from the post endpint. So you have to think about the best way to gather the information you want.

Perhaps you can use the user endpoint to get a list of users first and match it in your app to the infos that you already have.


#13

Maybe this will help you.
https://audacitus.com/site/2017/03/02/wordpress-rest-api-to-ionic-2-converting-category-id-to-name/