Hi and thanks for your message.
There’re two different arguments; “year” and “released”. The latter gives you something like “31 Oct 2013” (if available).
Using thousands separators can be done by using the PHP function number_format().
Thread Starter
selse
(@wwwp)
I’m using both “year” and “released”, both of them return the same value (year only). I guess (maybe) this because the data provided by omdbapi.
As the thousands separator, how to implement the function to the plugin? Really sorry about this, not PHP savvy here just an ordinary shortcode user π
What movie are you using?
PHP’s number_format() function works like this in PHP:
<?php
$movie_title = "Avatar";
$votes = imdb_connector_get_movie_detail($movie_title, "imdbvotes");
$votes = number_format($votes, 0);
echo "The movie $movie_title has $votes votes.";
I’m just realizing you’re right. For some reason, with caching enabled, it only displays the year. I’ll fix it and let you know here.
Thread Starter
selse
(@wwwp)
Thanks for the updated plugin for the fix.
As for thousands separator, since I don’t know how to add the function to my theme functions so it can work with existing shortcodes ( actually I don’t know any PHP at all π ), I had to hardcoded this line $value = number_format($value, 0); to plugin’s functions file.
So it goes from this
/** Remove everything but numbers from imdbvotes */
if($movie_detail === "imdbvotes") {
$value = preg_replace("'[^0-9]'", "", $value);
}
to this
/** Remove everything but numbers from imdbvotes */
if($movie_detail === "imdbvotes") {
$value = preg_replace("'[^0-9]'", "", $value);
$value = number_format($value, 0);
}
Works great as I needed, the only con is if plugin update available. I have to add that single line again manually to the function. No problem here as long as the function work properly and no conflict/error appear.
No need for that. I’ve implemented a filter that allows you to overwrite the output. Please download this version of the plugin and replace it with the old one (it will be included in the next version as well, so updates won’t destroy anything).
Then, open your functions.php in your theme directory and add the following:
/**
* @param $movie_details
*
* @return mixed
*/
function imdb_connector_number_format_votes($movie_details) {
$movie_details["imdbvotes"] = number_format($movie_details["imdbvotes"], 0);
return $movie_details;
}
add_filter("imdb_connector_movie_details", "imdb_connector_number_format_votes");
That’s it already.
Thread Starter
selse
(@wwwp)
Big thanks for that man, the last one works perfectly great. You solved all of my problem. Cheers π
You’re welcome, glad I could help π