JSON Data Source asset and WP REST API


(Ryan Archer) #1

Using the JSON Data Source asset to connect to a posts within a Wordpress blog using the WP REST API plugin https://wordpress.org/plugins/rest-api/.

 

Since version 2 of this Wordpress plugin, there has been a noticable change that I'm confused about. It puts {"rendered":" in front of all the content.

 

When I've successfully connected to the WP blog posts data and pull it back using the JSON Data Source asset, it keeps this text in all the entries. When using an asset listing (with keywords) to list out the blog posts - this unwanted content comes through.

 

It does not come through in older JSON feeds that are rendered with v1 WP REST API - only the latest version. To compare the feeds:

 

1) This is an example using v1.0 WP REST API plugin: http://rachelbaker.me/wp-json/posts

2) This is an example using the latest (2.0) WP REST API plugin: http://coolwebs.com.au/wp-json/wp/v2/posts

 

Trying really hard here but cannot remove the {"rendered":"  characters that it inserts into the content. Example is below:

{"rendered":"Urban Paddock Sydney is LIVE"}
{"rendered":"Coolwebs (Gold Coast web design) is pleased release Urban Paddock Sydney website upon the world http:\/\/urbanpaddocksydney.com.au Website has been custom built on a solid and popular Content Management System using lots of big beautiful pictures, parallax scrolling effects and elegant use of minimal text. The result is a clean smooth...
Featured media: 3166
View post

Is there a way to remove these extra characters without having to resort to some weird RegEx trickery?


(Aleks Bochniak) #2

Modify v2 of the plugin, or stick with v1


(Peter McLeod) #3

Hi 

 

Can you just modify how the data that is being returned from the API is accessed to match the new API model?

 

Eg - the 'content' key has a value that is another object, so just get the value for its key 'rendered':

 

obj.content.rendered 

 

So if you are using a JSON data source asset you would need to update the data attributes to reflect this change.

 

Thanks

Peter


(Ryan Archer) #4

Aha! Think I have solved it by using JSON Data attributes. JSON Data Attributes http://forums.squizsuite.net/index.php?showtopic=13427&hl=

 

Just put in content.rendered and title.rendered in the data attributes field in the details screen. Then use the appropriate replacement keywords, %ds__content.rendered% and %ds__title.rendered%

 

Coming along well.


(Ryan Archer) #5

Thanks Peter, I think you submitted your reply as I typed up my solution above.

My remaining issue is how to get an image src value for featured image that's related to the post. So far this has stumped me because it is within a JSON feed of it's own refered to as "FeaturedMedia".