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) {
…
}
Related
The filter "woocommerce_product_get_price" to show a custom price works but casually I have discovered that this filter is triggered five times in single product page and six times in the archive product page. This I have checked including a var_damp in the following way:
add_filter('woocommerce_product_get_price', 'get_ws_price', 10, 2);
function get_ws_price($price, $product){
var_dump('HI!');
$price = 99.99;
return $price;
}
This is a problem for me, I use this filter to perform complex code and is repeating them many times.
What am I doing wrong?
Is there another way to modify the price of the product with another hook?
WooCommerce also has this problem which it solves by caching. It uses the WordPress get_transient() and set_transient() to save a version in the WordPress database. This allows the calculation to be used over multiple requests. Further, the calculation is saved in a global object so that within a single request the calculation can be retrieved from an in memory object.
WC_Product_Variable_Data_Store_CPT::read_price_data() in file '...\wp-content\plugins\woocommerce\includes\data-stores\class-wc-product-variable-data-store-cpt.php' is a good example of this technique.
You could choose to not use the filter and write your own function to replace get_price_html(). With the new function you can overwrite your WooCommerce templates such as the single product page woocommerce\templates\single-product\price.php and replace any calls to this function with your own custom function. This way it will only be called once.
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 have a wiki built with drupal, with a taxonomy category Workgroup, assigned to both the users and the articles. I am using apache solr search module with facet api and my end goal is to set up the search so that by default when users search for the articles, only articles from their workgroup are shown.
That is, when they launch the search from a search box, they should get the same results as for /search/site/hello?f[0]=im_field_kb_workgroups%3A4529 (where 4529 is one workgroup id) instead of just /search/site/hello (current behavior) Users should still be allowed to search in other workgroup facets when they want, by removing the checkbox in the facet block.
I have this working almost by hacking the apachesolr module (not recommended I know but really want this to work). In the function apachesolr_search_custom_page_search_form_submit, I have:
// Get the workgroup id
global $user;
$account = user_load($user->uid);
$user_kb_wg_fieldinfo = field_get_items('user', $account, 'field_kb_workgroups');
$user_kb_wg_tid= '';
if ($user_kb_wg_fieldinfo) {
$user_kb_wg_tid = $user_kb_wg_fieldinfo[0]['tid'];
}
// Add the solr filter for this workgroup facet so that by default, search results are
// fetched only from that workgroup.
if ($user_kb_wg_tid === '4529') {
$get['f[0]'] = 'im_field_kb_workgroups:4529';
}
This does the job but the problem is that this relies on the apachesolr search form. I have users coming to the wiki by searching from sites external to the wiki, where the wiki search form is just a simple POST form pointing to the KB domain and the path /search. So this will work only when people are searching from inside the wiki, where I present them the apachesolr search form.
I have investigated some other options:
In my custom module, I implement this hook (without the user workgroup checks for now, for testing):
function kb_hacks_apachesolr_query_prepare($query) {
$query->addFilter('im_field_kb_workgroups', '4529');
}
This filters the results from searches everywhere, but the filter is applied all the time, and users don't get to deselect this or other filters. (in fact, other filters appear only when passing the filter as a GET param like above with f[0])
I also played with the url_inbound_alter hook, but could not figure out how to pass the solr query param as GET. The following did not work.
function kb_hacks_url_inbound_alter(&$path, $original_path, $path_language) {
if ($path == 'search/site/hello') {
$_GET['f[0]'] = "im_field_kb_workgroups:4529";
//$_GET['f[0]'] = "im_field_kb_workgroups%3A4529";
//$path = 'search/site/hello?f[0]=im_field_kb_workgroups%3A4529;
}
}
Is there a way to set GET params from this hook? But even if this had worked, I would still have to figure out how to do this only by default (when the search form is submitted), and not when the filter itself is deselected. Is there a way to detect checkbox changes in the facet block?
Maybe there's another way to do this? I have been stuck here for the last two days and would really appreciate any help I can get. Thanks!
You can add a relationship to the taxonomy term "Workgroup" and use a contextual filter for the current user. In the contextual filters section, you can change the behavior when the filter is not present.
I am trying to build a "Latest Comments" widget for Orchard CMS.
I know I could directly query the SQL, but is there an API I can use in Orchard to get the latest comments on the whole blog (and which blog post each comment belongs to, etc)? I've been looking at IContentManager::Query, but I'm not exactly clear how I can use this to get the information I want.
Check out the CommentsService in the Orchard.Comments module. Orchard.Comments.Services.CommentsService. It's really close to what you need. Since the service returns the query, you could just tack on some additional sorting like this...
var query = commentsService.GetCommentsForCommentedContent(blogId);
var comments = query.OrderByDescending(c => c.CommentDateUtc).Slice(10);
Something like that.
...or, in other words, how to create a simple join as I would do in SQL?
Suppose I want the following information:
Just as an example:
a person's full name
a person's hobbies.
His full name is in a (content profile) node type 'name_and_address' and his hobbies are in 'hobbies'.
In SQL, I would link them together by node.uid.
I've seen a bit about using relationships, but that goes with user-node-refs.
I just want the same user from one content-type and the other.
Now how could I get his name and his hobbies in 1 view?
There is a how to here does this do the job?
If not...
Views can be extended with custom joins, filters etc. If you are lucky there will be a module for this already. Some modules even provide their own views plugins.
You can write your own views plugins, although the documentation is a little fragmented.
The other thing that should be noted is that views isn't always the answer. Sometimes writing a custom query and display handler will do what you want with much less hassle.
Look at the relationships section of the view. This allows you to relate (ie join) different types of content (ie tables). It's not especially intuitive to someone used to SQL, but this video explains much of it. http://www.drupalove.com/drupal-video/demonstration-how-use-views-2s-relationships
You could use views_embed_view() in your template files to manually specify where they appear (and by extension render one view right below another).
You could override this function in a custom module (modulename_embed_view($name, $display_id)) in order to selectively edit what data is allowed out to the page.
Ex):
function modulename_embed_view($name, $display_id) {
if (strcmp($_GET['q'], 'node/123') === 0) {
$view = views_get_view($name);
$view2 = views_get_view('second view');
$output = $view['some element'] . $view2['element'];
}
return $output;
}
I know that this is very much a hack - I just wanted to show how one might use php to manually render and modify views in your template files.