I woocommerce you can create Attributes, like Color
These attributes can have terms, like red, green, white. Later on, you can add these attributes to a product.
I know how to add these attributes by means of the API, like described here:
http://woothemes.github.io/woocommerce-rest-api-docs/#create-a-product-attribute
I've been searching for hours, but there seems to be no way to add terms with the API. Am I missing something?
You add terms with the Update A Product api, here:
You make a PUT request: /wc-api/v3/products/<id>
In the request body you send:
{"product":{"categories":[...],"tages":[...]}}
Since WooCommerce 2.5 you have new endpoint for adding attributes term. Just look at the documentation.
http://woothemes.github.io/woocommerce-rest-api-docs/#product-attribute-terms
For example for creating term for the specific attribute you can POST to endpoint
/wc-api/v3/products/attributes/<attribute_id>/terms
JSON message:
{
"product_attribute_term": {
"name": "Black"
}
}
It accepts the attribute slug/taxonomy name; Just use this one:
example.com/wp-json/wc/v3/products?attribute=pa_compatible-for&attribute_term=249
I know it's not documented properly!
Have a good time.
Related
Using the WooCommerce API I want to send an HTTP GET request to download all products with a specific attribute.
The documentation says the URL to do this with is this
/wp-json/wc/v3/products
And I can add parameters to the URL in order to filter the products.
I have successfully added filters for page and page count:
wp-json/wc/v3/products?per_page=100&page=10
I have also managed to get only available products with this parameter:
wp-json/wc/v3/products?&stock_status=instock
However, I cannot manage to add a filter for the attributes. I have tried the following ways to write the URL and non of them work
wp-json/wc/v3/products/?attribute=1
wp-json/wc/v3/products/?
wp-json/wc/v3/products/?attribute_pa_емаг=Да
wp-json/wc/v3/products/?filter[pa_емаг]=10
What would be the correct way to write the URL?
(Note: The attribute is pa_емаг and its value is Да)
The correct call would be:
/wp-json/wc/v3/products?attribute={attribute-taxonomy}&attribute_term={term-id/tag_ID}
Where attribute-taxonomy would be full slug in your case "pa_емаг", and term-id/tag_ID the id of "Да".
I'd like to use the Envato API to download a list of plugins for WordPress available on Code Canyon. However I have been unable to find a way to do so.
For example, I tried to use a get /search/item per their documentation using the parameter category and setting it to "wordpress" however this returned a number of results but nowhere near the 6,040 the site says it has.
The document also mentions the "category code" is what I should be entering as the parameter for "category" but it never defines the category code - unfortunately, this seems common throughout the documentation - there isn't any definition. Another example of this is calling get /catalog/collection. The parameter required is "id" which it describes as "The numeric ID of the collection to return" - but what numeric ID? This one wasn't hard to figure out, if you open a collection the url looks like:
https://codecanyon.net/collections/4945814-about
And the numeric portion is the ID...but I sure could wish for more definitions or examples of what the parameters should look like. :-)
I looked around, but didn't find anything helpful on the web nor does there appear to be a forum hosted by Envato for discussing the API.
Any help is appreciated!
Please find the code which I did to fetch data from envato API :
var themeforest_api="http://marketplace.envato.com/api/v2/new-files:themeforest,wordpress.json";
$.getJSON( themeforest_api, {
format: "json"
}).done(function( data ) {
var html='';
$.each( data['new-files'], function( i, item ) {
html=html+'<li><img src="'+item.thumbnail+'"></li>';
if ( i === 8 ) {
return false;
}
});
$("#all_items").append( html );
});
Hope it will help you for your one too.
I'm registering a custom taxonomy for my blog using the register_taxonomy function which has an argument rewrite
for rewrite the URLs using some parameters
, one of them is ep_mask . Wordpress claims that it should be used when you want to add an endpoint for the Taxonomy URL. I just don't understand why to add an endpoint and what it's benefit. Please if an example with a result is available it will be better.
Thanks in advance
The endpoint mask value is used to tell WordPress what kind of endpoint additions a certain registered item supports, and to which a developer can add
endpoints to via add_rewrite_endpoint().
By default taxonomies (as far as I know) offer no ep_mask (defaults to EP_NONE), but for custom taxonomies you could use a custom EP mask, or one of the built-in ones (e.g. EP_PAGES) to make the permalink structure work similarly to something else.
Assuming you set the ep_mask value to EP_PERMALINK | EP_PAGES, you could then register a new endpoint using
add_rewrite_endpoint('json', EP_PERMALINK | EP_PAGES);
Which in turn would allow you to suffix your taxonomy URLs with json and the value json would be available as a query variable in $wp_query. Then you can use the value as a check to alter the query, templates, and other related things when the page loads.
You can read more about endpoints here: https://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/ (A bit old, but should still reflect how the core works with endpoints.)
The benefit is that you can use the endpoint with pretty permalinks.
If you do not specify the EP_MASK, pretty permalinks will not work
The description of ep_mask in the documentation of register_taxonomy() contains a link to an article that explains it in detail.
A quote from that article:
If we wanted to add our endpoint to all post permalinks we would use EP_PERMALINK. For both posts and pages: EP_PERMALINK | EP_PAGES. For posts, pages, and categories: EP_PERMALINK | EP_PAGES | EP_CATEGORIES.
There are specific examples in that article:
https://make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/
Let's suppose I have Posts and Comments collections. A Comment record contains the attributes comment and postId. A Post record has a title attribute.
Now I have a separate page for a single comment (very unlikely irl, but just for the sake of it) where I want to show the comment of course but also the Post title. How would I do this, or more in general: how do you reference an attribute from a "parent" (parent between quotes because Mongo is not a referential database)?
One option I often see is to denormalize and also add the Post title as attribute to the Comment record. Although I do see use cases for denormalization, I am worried about the maintenance nightmare. When the Post title gets update, you also need to update them in all other collections where it is used as denormalized attribute.
So, my solution would be to subscribe also to the Post on the Comment page. Then in commentDetails.html I have this:
{{post_title}}
And in commentDetails.js I would have this:
Template.commentDetails.helpers({
post_title: function() {
return Posts.findOne({_id: this.postId}).title;
}
});
Is this the way to do this?
Edit: clarified the question and updated the example.
After being pointed on Reddit to a detailed article about this subject, I have implemented as the "naive approach" for now. I am looking into option 4 to make it really reactive.
I am using the JoeBlogs .Net wordpress wrapper by Alex James Brown. It just essentially makes all of the XML RPC calls available to .Net.
I have been using the GetRecentPosts(5) call, e.g. "Grab the 5 most recent posts", but this returns everything from the entire blog.
What if I want to simply grab the latest posts within Category X?
E.g. I want GetRecentPosts("My Category", 5);
Is this possible with the current XML RPC API?
I really don't want to have to resort to pulling down 20 ALLRecentPosts and then sub-filtering by category, because that will be so inefficient, as I will have one site calling the blog site to fetch this data..
Many thanks.
I don't think there is a default XML-RPC method that does this. However, you can add new methods by hooking into Wordpress's xmlrpc_methods filter (see below), although presumably that would mean you'd also have to add some code to your .Net wrapper.
add_filter('xmlrpc_methods', 'add_xmlrpc_method');
function add_xmlrpc_method($methods) {
$methods['foo'] = 'bar';
return $methods;
}
function bar($args) {
…
}