Ordering WordPress Posts By Any Order May06

Ordering WordPress Posts By Any Order...

WordPress has a lot of really clever ways to order posts, which can be used to order in almost any way. However, during a recent project I needed to order posts based on one of their meta values, but those meta values needed conditional if statements in to denote what values they should take. The scenario was such that I needed to order posts based on a numeric value in their meta values, ascending in number, but if that meta value did not exist, or was 0, to be placed last. So I wanted an order along the lines of: 2, 25, 39, 48, 0, null, null At first this seemed impossible, and I was left head scratching on how to carry out the order while still including core WordPress mechanisms such as paging. WordPress, by default, doesn’t include an orderby clause where you can just set post ID’s (ie order => (8,99,102,45,22) ). But then I remembered that since version 3.5 WordPress added this clause: ‘post__in‘ – Preserve post ID order given in the post__in array (available with Version 3.5). I then realised, that if I created an array in the right order, and then passed that to the post__in array I could achieve my desired result. Final code is below: PHP $arr = array(); // First loop through all posts and create an array of the post_id (key) to meta_value_num (value) $args = array('nopaging' => true); $query = new WP_Query($args); if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); $exp_date = get_post_meta(get_the_ID(), 'the_meta_value', true); // If the meta_value is null or 0, make it huge so we can order accordingly if($exp_date == "" || $exp_date == "0") $exp_date = "999999999999"; $arr[get_the_ID()] = $exp_date; endwhile; endif; wp_reset_postdata(); // Sort the array in ascending order asort($arr); $args_posts_in...

HDR Playtime Feb26

HDR Playtime

Over the past 2-3 years I’ve started to invest a little more time in the art of photography; trying to capture that perfect shot that epitomises the feeling and scenery that I see infront of me, get the awe and wonder of nature into a little rectangular world for others to see, and to try and convey the natural beauty of some of the places that I’ve frequented on my travels. More often than not I fail quite miserably, but this hasn’t stopped me progressing and looking at new techniques to try and advance the craft. Which is why about a year ago a photo and corresponding article on HDR photography caught my attention. HDR (high dynamic range) photography is basically the art of taking 3 photos of the same scene, at different exposure levels, to capture the full dynamic range of colours. Or as wikipedia likes to say: “High Dynamic Range Imaging (HDRI or HDR) is a set of methods used in imaging and photography to allow a greater dynamic range between the lightest and darkest areas of an image than current standard digital imaging methods or photographic methods. HDR images can represent more accurately the range of intensity levels found in real scenes, from direct sunlight to faint starlight, and is often captured by way of a plurality of differently exposed pictures of the same subject matter” In its basic functionality / my basic process flow it’s taking a photo 3 times, at different exposure levels, overlaying them in a nifty little program and playing with some levels to get your desired result. Around 90% of the time I find that I’m not sure if I like the HDR version more than the original, but now and again the new full dynamic ranging photo seems to work out beautifully and I’m...

Nike API PHP Example Feb20

Nike API PHP Example

Recently Nike released their developer site to give people a preview and a glimpse into how they will be able to access and export Nike data through their upcoming API. The problem being is that it’s still in development stage, and for users like me, who aren’t part of (or won’t be part of) their Nike+ Accelerator Program, it doesn’t actually give you access. But it does expose quite a few parts that with a little tinkering, console debugging, and help from the ol’ t’internet you can figure out the core concepts and key attributes and write your own PHP script. It returns the information in lovely JSON format which can easily be used and manipulated to your hearts content. [php] $curl_handle=curl_init(); $data = array(‘appid: fuelband’, “Accept: application/json”); curl_setopt($curl_handle,CURLOPT_URL,’https://api.nike.com/me/sport?access_token={access_token}’); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); curl_setopt($curl_handle,CURLOPT_HTTPHEADER,$data); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); $buffer = curl_exec($curl_handle); curl_close($curl_handle); if (empty($buffer)) { print “Sorry, something went wrong here”; } else { print $buffer; } [/php] Simple hey! The {access_token} is a personal ID related to your account, that you can generate from the Nike Developer Site. The URL can take various formats, depending what you want to grab, The URL above: [code]https://api.nike.com/me/sport[/code] Simply grabs an overview of my activity: [code] { “experienceTypes”: [ “ALL”, “RUNNING” ], “summaries”: [ { “experienceType”: “ALL”, “records”: { “lifetimeFuel”: 64631 } }, { “experienceType”: “RUNNING”, “records”: { “level”: 3, “lifetimeDuration”: “29:17:42.000”, “lifetimeGpsRuns”: 29, “lifetimeHeartActivities”: 0, “lifetimeAveragePace”: 348832.2388571808 } } ] } [/code] But you can also use these URL’s to get more information: https://api.nike.com/me/sport/activities 1 https://api.nike.com/me/sport/activities https://api.nike.com/me/sport/activities/%activityId% 1 https://api.nike.com/me/sport/activities/%activityId% https://api.nike.com/me/sport/activities/%activityId%/gps 1 https://api.nike.com/me/sport/activities/%activityId%/gps The last one giving you full GPS data of an activity. A big hats off to WotLabs that basically gave me the last piece of the pizzle, the...