I'm using WordPress REST API and can receive data from https://websitename.com/wp-json/wp/v2/posts?_fields=author,id,excerpt,title,link,featured_media_src_url.
The problem is featured_media_src_url is added with This WordPress Plugin and I can't retrieve it using URL filters. (it works by fetching just .../w/v2/posts without params)
It looks like the plugin gets the path using featured_media which returns an id. Adding this to the fields solves the problem:
https://websitename.com/wp-json/wp/v2/posts?_fields=author,id,excerpt,title,link,featured_media_src_url,featured_media
Related
What might be a reason?
Trying to batch update product images (and price) in WooCommerce via REST API. Images already exist in wordpress media library and links are correctly copied. However, instead of using image it creates new image.
Request: POST.
URL: https://SiteURL/wp-json/wc/v2/products/xxxx?consumer_key=c______&consumer_secret=_____
Body:
{"update":[
{"regular_price":"448",
"images":[
{"src":"https://urlToImage.jpg",
"position":0, "name": "test"}
],"id":"xxxx"}]}
In response I can see it creates image with the same url but as there is already an image in the library, it adds -1 to url.
Thank you in forward :)
Since this is an update where the images already exists you need to set the id member of the images element. Otherwise, WooCommerce interprets this as a request to add a new image to the product gallery.
I'm trying to use the Wordpress API (version 1 - not the new Rest API) to retrieve blog posts from various sites. However, I noticed that it was not retrieving the "featured" posts, only normal ones.
The API call I am using is: https://public-api.wordpress.com/rest/v1/sites/$site/posts
Is there a way to retrieve all the posts (normal and featured)?
Thank you!
User tried and confirmed to be working
https://developer.wordpress.com/docs/api/1/get/sites/%24site/posts/
There's a Query Parameter called 'sticky'.
I'm using the WooCommerce REST API (http://woocommerce.github.io/woocommerce-rest-api-docs/#introduction) and are able to download Customers, Orders etc successfully.
My customer has added some custom fields to the checkout page, e.g.:
po_number
accounts_email
I would like to be able to GET these custom fields when requesting an ORDER, e.g.:
/wp-json/wc/v1/orders/4568
At the moment none of the custom fields are returned when I GET an Order. I've tried adding
?filter[meta]=true
to the request URL but that doesn't make any difference. Is there a way I can modify the GET URL to include all custom fields? Couldn't find any reference in the REST API docs to custom fields.
I have struggled like you did, but then it turns out using the newer v2 REST API solves the issue for me. So instead of:
/wp-json/wc/v1/orders/4568
I now use:
/wp-json/wc/v2/orders/4568
And custom fields will be included in the response with the key meta_data, even with those hidden fields starting with _.
so, I have a Wordpress Setup with a custom homepage template. In the template I query some products from an external database. Now I want to create a detail of a product, and this is where im stuck..
I don't know how to implement this since there is no data in the WP db thus no actual url (I guess?).. I thought about making 1 page in WP called 'Detail' and make the href attribute on the homepage products like this 'www.example.com/detail/123', get the id from the url en with that id query to the database..
Is this the right approach? Hope someone can help..
thanks!
If i understand you right, you want to query content from one wordpress website to another right ?
The right way to do it is to use JSON APIs which will let u retrieve the content you need using HTTP requests.
You can set these APIs yourself, refer to the following tutorial.
Thus, you can also use this wonderful wordpress plugin :
JSON API
After installing and enabling the plugin you'll have to set your API links according to the content you need to get, for example the following api:
http://example.com/api/get_posts/?post_type=custom_post_type&count=3
queries the latest 3 custom posts along with their fields and custom fields (if present).
Find more examples here.
Now on your other website where you want to display the content you 'll need to use JSON decode to convert the JSON string into a PHP obect or array.
For example:
$json = '{"a":hello,"b":hi,"c":hey,"d":yo,"e":ola}';
$data = json_decode($json);
echo $data->{'a'}
// this should echo the value "hello"
As stated here.
I hope that helps !
I don't think he wants to query another WordPress. He only says that he fetches data from another database that contains products.
Your idea is pretty close to what you have to do. Take a look at add_rewrite_rule, add_rewrite_tag and get_query_var.
This tuts is a good example for you: http://code.tutsplus.com/articles/custom-page-template-page-based-on-url-rewrite--wp-30564
Using mailchimp to send RSS-driven campaigns. Fetching the RSS from a WP installation. This works fine.
In the end of the email I want to add one RSS-item from another source with mailchimps merge tag *|FEED|* as shown in this tutorial: http://kb.mailchimp.com/article/how-can-i-add-any-blog-post-to-a-regular-campaign
I got this to work with a static URL. But I want to use different URL:s depending on the recipient. I've saved the URL:s with mailchimps API in a merge tag called *|USER_FEED_URL|* and I can print this URL perfectly, but is there a way to use the feed tag with my user_feed_url and fetch the RSS?
Tried: *|FEED:*|USER_FEED_URL|*|*
But it only print: *|FEED:http://theuserurl.com/feed|*