How to get posts orderby comment_count ascending and where to place the code? (Wordpress REST API) - wordpress-rest-api

I am a complete beginner when it comes to extending Wordpress REST API. I need to extend the API so that a request to /wp-json/wp/v2/posts?orderby=comment_count&order=asc would yield a response with posts that are ordered by comment count in ascending order ie. posts with the least amount of comments appear first.
I skimmed through the REST API Handbook and watched a couple of YouTube videos, but found no answer to my problem. I found this answer and it looks promising, however I'm not entirely sure if the code provided there fits my needs. From what I could gather WP_Query class is what I'm looking for, but I don't know how to make use of it. My second problem is that I don't know where exactly to place any code I may have stumbled upon ie. which file is supposed to play host to the code eventually?
I would greatly appreciate detailed answers and possibly sources for more information regarding this topic.

According to WordPress documentation orderby only accept following parameters:
author, date, id, include, modified, parent, relevance, slug, include_slugs, title
But you can add custom parameters to orderby if you have access to Wordpress website code. Please follow the below URL:
https://www.timrosswebdevelopment.com/wordpress-rest-api-post-order/
Let me know if you need more help.

Related

How to query the iTunes API for movies in a specific genre

I am trying to query the iTunes API for movies in a specific genre. I have been searching for hours now but can't seem to figure it out.
Example: https://itunes.apple.com/search?term=james+cameron&limit=25&entity=movie
This will give me a list of movies made by James Cameron, but I wan't to search for all the movies that match a specific genre, ex: "Romance".
When I look at the documentation here: https://affiliate.itunes.apple.com/resources/documentation/itunes-store-web-service-search-api/
It states that I can search for attribute=genreIndex, but I can't find anywhere this 'genreIndex' is specified. So I have no idea what to put in here? - I found several other questions relating to the same, and they all link to this: https://affiliate.itunes.apple.com/resources/documentation/genre-mapping.html
Which no longer exists?
Is there something I don't understand, or how am I supposed to do this?
Thanks! :)
This solutions is not in the iTunes documentation, I found it by trying around. (I think that 'genreIndex' might be deprecated, and is now 'genreTerm' (Maybe Apple forgot to update it on the documentation). However, this works perfectly:
https://itunes.apple.com/search?term=romance&entity=movie&attribute=genreTerm

Displaying most popular post on Tumblr blog

I've been tasked with adding "Most Popular" functionality to a Tumblr blog. Essentially, when the Most Popular button is clicked, I need to display either a single post, or a list of posts, ordered by their popularity. The popularity will be calculated based on the number of "notes" that the post has.
Does anyone have a suggestion on the best way to go about this? I can't find anything baked into their theme customization at http://www.tumblr.com/docs/en/custom_themes#search. Is going the API route the only way to accomplish such?
Well, I'm no expert with Tumblr but I have worked a fair share with the API for a project I'm developing. From my experience it seems you would need an API to get all of the posts note count. Using a theme I know to order the posts shown on the page without an API key, but to go further back you'd have to use a javascript plugin or just use the Tumblr API (it's surprisingly easy to use)
From my short time I just spent thinking about the issue, you could put a NoteCount on each of your posts (hidden with CSS or not; up to you) and then use the API's notes_info to obtain all of those numbers and compare them. You'd then store how ever many posts you want (according to the note count) in an array and use that array on the page you want. It seems like a lot of work, but I'm not sure how else you could do it
EDIT
After investigating the issue a bit, I found that note count is far from a consistent feature on Tumblr. There is no one class that all note counts share nor is the text around it consistent. It seems that you would have to do it on an individual blog basis. Once you obtain the HTML for the posts, through a script or the API, you can run a function similar to the following which uses regex to detect where the note count
var posts = document.querySelectorAll('.post'), // Get all posts (*most* blogs have this, not all)
noteExpr = /with ([0-9]+) notes/, // Get any numbers between "with " and " notes"
noteCounts = [];
// Creates an array filled with all of the note counts
for(var i = 0; i < posts.length; i++) {
noteCounts.push(noteExpr.exec(posts[i].innerHTML)[1]);
}
// Do something with noteCounts
Demo, using posts from one of my favorite blogs MotionAddicts
Some more examples using sites I look at:
For 58 notes use />([^>]+) notes/
For <div class="notecount">Notes: 218</div> use /Notes\: ([^>]+)</
The downside is this has to be customized for each blog if they vary in the format, but it is the only way I know how to without using the API, even then I'm not sure there is a better way
Other info:
Studiomoh had a similar plugin but it only works for pictures
Example of how to include a NoteCount
How to include a note count when there are no notes

modx replacing article link with a link of categories

I've got a staging and live site I'm working on (not my code base). I've accidentally replaced the live server with some staging code (no backup (slap me)) and I'm getting weird urls for articles on the sites 'blog' page.
Basically everything's being called into the page correctly but the page header link is being screwed.
Rather than being
http://www.example.com/a-nice-url
it's giving me
http://www.example.com/news,recent,pr,etc
which appears to be the list of categories of the article.
Where/How can I easily fix this?
I'm only calling [[*content]] and can't find where that is.
Linking to an article I know is there with the correct url works still.
any ideas would be greatly appreciated.
I assume your blog page has some sort of listing somewhere, maybe a getResources call? If you can't find it in your blog list template (as you're saying you only see a *content), it means the list is probably "hardcoded" in the blog list resource content field.
You'll want to find the chunks being used to output each blog entry on the lists and check which page parameter is used to construct the link. It should probably be *alias, and if it is and your aliases are correct you have some deeper trouble going on.

Can I limit the data elements received from the FB Comments Plugin?

I'm looking to add the Comments Plugin, but wish to keep the comments simple. I'd like to have just the user-photo and comment visible. Not the date of comment, reply, like, etc.
Please advise if this is possible and how one can restrict this.
Thanks very much...
Andy
This isn't possible any more. Previously, there were ways to override comment box CSS, but these were removed with version 2 of the plugin. So, you're stuck with what Facebook provides.
It's possible to post and retrieve comments using the Graph API, which would allow you to style them yourself - but it would require a fair amount of technical work.

How to Style Facebook Activity Feed

How do you implement custom css on a Facebook activity feed plugin? This related post does not fully answer the question. Is this the right way?
Where does the
<fb:tag name='link'></fb:tag>
go? Inside of of the
<fb:activity site="..." app_id="..." ></fb:activity>
outside of it, before or after? I'm sort of confused...
the only way i use activity feed is when its in a widget that will generically upate in all posts. Anyone who inserts these snippets into blog posts or other 'hard to find and edit later' posts and pages, will regret it
Why?
Because Facebook changes their script every month or so and the script snippet you inserted wont work anymore
I have hundreds of blank areas in blog posts where i inserted an activity feed and the script always stops working after some weeks when fb adds some code or changes the location of some script or renames a file and the old script has no canonical or generic way of readjusting.
There is no point in using a script which gets made obsolete every month and you then need to find all posts where you inserted the snippet and change it for the new working code.
Im always having to reinsert new code into my fb social widgets because they cease to function...
Not viable unless you take it into consideration. Only insert in spaces where oyu wil notice it when it stops working
As Facebook Answers answered, you cannot really style it with a custom CSS, nor via JS, as the activity feed widget creates an iframe.
The info from martincarlin87 is useful, but that is not exactly what you get with the Activity Plugin, which is what you meant I guess:
http://developers.facebook.com/docs/reference/plugins/activity/
For using this you cannot really interact with the Facebook API, it is a little world apart. By now... (July 12th 2012)
Facebook PHP SDK: https://github.com/facebook/php-sdk
Comes with some simple examples, I would suggest uploading it to your server and tinkering with it, Facebook has a steep learning curve but here at Stack Overflow there is even a Facebook section: facebook.stackoverflow.com so just take each step at a time and if you can't get it by reading the facebook docs: developers.facebook.com then you can always ask here and I'm sure someone will be able to help you.
Getting Started: http://developers.facebook.com/docs/reference/php/
Once you have made an app, you add it to your fan page and then you will be abel to test what information you can get using the Graph API Explorer: https://developers.facebook.com/tools/explorer
That post you refer to is a red herring I'm afraid. If you put any HTML between the activity tags it gets rendered BEFORE the iframe is added. So its a no starter, from what I can see. However, I eventually found a solution, which I gave on that thread. I am repeating it here in case somebody searching doesn't see the other thread.
I managed to customise an Activity plugin, after a great deal of effort.
You can see the result here:
http://www.quniverse.co.uk/shopdata/about_us.php
Feel free to post a comment on that site, it exists purely for test purposes so I'm not fussed what goes up there provided its clean.
I explain how I achieved this in the blog article posted here:
http://facebookanswers.co.uk/?p=302
To summarise briefly:
You cannot insert CSS into the activity plugin.
Rely on the fact it has a transparent background, and supply your own.
Turn off the header and supply your own.
You can specify a light or a dark font, a few fontfaces and a border colour.
If you read the blog article you will get a full explanation.