Support » Plugin: IMDb Connector » Get the frontend/output of meta_value

  • Resolved ZaddKeefer

    (@zaddkeefer)



    Hey guys!

    My problem is I want to order posts with the meta_key “rating”, but the problem is the meta_value is a direct link to an IMDB movie (url) fetching the imdb rating and transform it into the imdb rating on output Is there a way around this, so it can sort by the transformed output and not the meta_value field that contains an URL?

    I use the plugin “imdb-connector” to help fetch and transform the rating, is there a way to use imdb-connector PHP functions to order the output from the meta_value field?

    My code:

    <?php
    if ($_POST['select'] == 'prijsn') { $order = "&order=DESC&meta_key=rating&orderby=meta_value";
    ?>

    Is there a way to implement the meta_value “rating” of meta-key to be the output on the site? with use of this code in some kind:

    <?php
    $rating="Rating";
    $imdbrating = get_post_meta($post->ID, $rating, true);
    $movie = imdb_connector_get_movie($imdbrating);
    echo $movie["imdbrating"];
    ?>

    https://wordpress.org/plugins/imdb-connector/

Viewing 13 replies - 16 through 28 (of 28 total)
  • Hmm, might be me there is a little off today.. Your code is something I probably want, I pasted your working file with the functions in my functions.php, if that can work?

    Then I tried to assemble your class onto my archive.php with this:

    <?php
    	$order = "&order=DESC";
    	if ($_POST['select'] == 'newest') { $order = "&order=DESC"; }
    	if ($_POST['select'] == 'prijs') { $order = "&order=DESC&meta_key=year&orderby=meta_value";  }
    
    		 $class = new IMDb_Movies();
             $class->set_update_interval(60, "minutes");
             $movies = $class->get_movies_by_rating();
    
             if($movies->have_posts()) {
    			while($movies->have_posts()) {
                   $movies->the_post();
    					 if ($_POST['select'] == 'prijsn') { $order = "&order=DESC&meta_key=rating&orderby=". get_post_meta(get_the_ID(), "imdb_rating", true) .""; }
    					}
            		 }
          ?>

    I am trying to make a sort functions and tried to fetch the id in my “orderby”, can you see a solution for this?

    Hmm my code seems to “kinda” work and yet not quite? One of my posts is not ordering at all, here’s an example of my posts ratings:

    8.8
    8.3
    8.1
    7.4
    -> 8.3 <-
    6.3

    That one post seem to be in an “unorder” something.. Might be my code? It almost works for me now

    Plugin Author thaikolja

    (@thaikolja)

    Do you have Skype to chat? No need to use microphone, just chatting is enough.

    Plugin Author thaikolja

    (@thaikolja)

    Or any other instant messenger? Or IRC?

    I do not got skype on my laptop.. only on my phone lol, but would be kinda awkward and complicated to have phone and laptop on the go – I got IRC and steam though, but it might be tomorrow am really tired for today..

    The weird thing is.. Some posts seem to work, except one and new posts I post seems to be out of order.. I dont know if it’s something to do with the imdb link? all other posts seem to order perfectly.. Except the one, and newly added?

    Plugin Author thaikolja

    (@thaikolja)

    Alright, then we’re gonna figure it out tomorrow in IRC. Let’s arrange to meet at 17:00 German time (UTC +1). I’ll be in the channel named #k on the server irc.rizon.net. My username will be kolja.

    Alternative, you can click here to connect if you don’t have an IRC client.

    I’m certain we can get it done tomorrow. Thanks for your patience after all.

    Rizon is what I use as well, will be on there around 17:00 hopefully! I live in Denmark so it’s same timezone

    Thanks for your patience, after all you are the one trying to help out!

    One of the problems might be because of “,” between decimals in the rating, such as “8,3” and not “8.2”.. I tried to manually sort by a number like “8.2” and not “8,2” and it worked.. IF YOU can find a way to replace the , with . might be the workaround!

    Plugin Author thaikolja

    (@thaikolja)

    Sorry, to be honest, I have absolutely no clue what you’re trying to achieve. The example code I gave you does exactly that: It lists posts ordered by their ratings. Isn’t that what you wanted?

    Let’s try it again. Download this file and put it into the directory of your current theme. It doesn’t matter where, putting it in the root directory of/wp-content/themes/<YOUR THEME>/works fine.

    Next, create 3 sample post entries for testing, each one is supposed to be a movie. Enter the movie title into the post title input text field. Now, very important: Hit “Screen Options” in the top right corner of the dashboard and select “Custom Fields”.

    Now you’ll see the custom field boxes somewhere below the content. Click “Enter new”, in “Name” of that custom field, enter “imdb_id” and in the “Value” field you enter the IMDb ID of the movie that you’re currently posting, for example tt1352369. (This step could be done automatically, but first we got to get this thing working).

    Here’s a SCREENSHOT.

    Publish the post and repeat the process with two new posts and different movies.

    After that, go to the “Pages” section, click “Add New” and choose “Movies” in the box labeled “Template form” (SCREENSHOT). Publish the page and open it. You should now see a result like on this SCREENSHOT.

    And finally, another SCREENSHOT that shows that the posts have been indeed ordered by their rating and not by their date.

    If it’s still not what you wanted, we’ll talk aout it tomorrow in detail. Good night.

    Yes this is actually what I wanted! And it worked perfectly on a template/page, it came out just what I wanted – But what I am trying to achieve, is a sort filter on the main page $_POST[‘select’], like &order=DESC&meta_key=year&orderby=meta_value etc.. except with your imdb rating – I want it to work with the template file you shared, so instead of an entire template of that exact outcome, I want it to work in my select->option.. Really tried everything to make this working in a dropdown – Like if they clicked on the <option> Rating</option> it will only show posts sorting by the rating, just like on your working template :)!

    Thanks for all this mate!

    Plugin Author thaikolja

    (@thaikolja)

    I must admit I still don’t know what exactly you need, but maybe this page template helps you in some way. “Install” it just like the template I’ve posted earlier.

    It queries all posts that belong to the category “movies”, so you need to add them. Then it displays the movies based on your selected “order by” and “order” settings.

    Here are some screenshots:

    1. Default settings; ordered by post date, descending.

    2. Listing movies ordered by their release year, ascending.

    3. Ordered by IMDb rating, descending.

    As I said your template works fine, and does EVERYTHING I want it to do :P, I want this to also work on my index, might just need to use the template code from the template source or adjust the template code to my index right?

    Plugin Author thaikolja

    (@thaikolja)

    Yeah, basically.

    $movies = new IMDb_Movies();
    $movies = $movies->get_movies_by_rating("desc");

    This will return $movies as a WP_Posts class you can use like any normal loop.

Viewing 13 replies - 16 through 28 (of 28 total)
  • The topic ‘Get the frontend/output of meta_value’ is closed to new replies.