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...

Jurassic Coast Challenge Apr04

Jurassic Coast Challenge

The hills were steep and often, the miles many, the terrain varied and frequently difficult, but the sun was shining and the steep hills, varied terrain and many miles were all part of the challenge as Han and I set off to try and complete a marathon a day for 3 days over the rugged Jurassic Coast down in south Devon. Travel back 6 months and it was yet another sunny day as Han came back from visiting her brother with knowledge of this formidable challenge now planted as an ever growing seed in her mind. She had seen some crazy runners plodding along the picturesque coastal path in Weymouth, around 15 miles into their 2nd day of the three 26.2 mile routes. “This could be a fun challenge?” she thought “Sounds like a whole lotta crazy!” I replied And so the seed took root, the seed grew, and the seed blossomed until we found ourselves listening to the organiser of the VoTwo Jurassic Coast Challenge explain the OS driven map route for day 1 of the 3 day event. The event in question was a 78mile route along the picturesque south coastal path starting at a non-descript hill 26 miles west of event HQ in Weymouth. Each day was a full marathon distance self-guided run (no markers or race signs), following the coastal path step for step, finishing up on Shell Bay a few miles North of Swanage 3 days later. The first day had a relatively late start of 11:30am, and as we watched the eclipse swallow the land into darkness before releasing its enveloping cloak to reveal a glorious sunlight day, Han and I took our tentative first steps on our mammoth journey. We had been casually pretending to not peak at the weather report the week before, not wanting to jinx the outcome in some form of uncertainty principle belief, and we had either played our cards just right, or more likely had lucked-out, as the sun was shining but not scorching, the wind was a confortable 4-5mph, and the first mile was a downhill saunter with wonderful vista’s of high rising cliffs and golden beaches ahead of us. We jogged on down, feeling light footed and free as the mass start of the 100 or so runners (and one dog) gradually thinned out and found their natural gaits and rhythms that would hopefully see them cross the finish line anywhere between 4 and 9 hours later. Day 1 would see two monster hills approach and test us within the first 4 miles, but at such an early stage of the challenge our legs were still fresh and still warming up, and the vistas that we were rewarded with were worth the un-guilty walking that had seen us slowly traverse the 200m peaks. We stopped and briefly ate at checkpoint 1 a quarter into the first days distance before hitting probably the hardest part of the full 3 days; around 2-3 miles of intermittent shingle beach. This stuff just sucked all energy out of you, as each step just jostled the stones beneath your feet as you sank into their opening and closing chasms of energy sapping hard work. “I think it will be easier if we just try and run across it” Han propositioned as she skipped elf like past every single other runner who was walking through the shingle pathways. Not one for being left behind I grumbled my ascent and 15 mins later we were out the other side and closing in on checkpoint 2. As we neared the half way mark of the day Han started to feel some pain in her left knee, but shrugged it off as we gorged our way through cheese and pickle sandwiches, my new running favourite of cheesy cheddars, while stuffing flapjack and some crisps for later consumption into my running bags pockets. As the...

A year later… and still running Feb24

A year later… and still running...

It seems fitting that one year on from the last post, as I was speedily traversing the southern hemisphere to see my sister in New Zealand, that I come back to revisit this blog and try and record once again life’s little adventures and twists and turns. It also seems strangely fitting that this new post, in an attempt to rekindle an online pubic diary of sorts, also starts with a running post, just like the first post exactly two years ago. Seems February is a chequered flag month for me, lets hope this one carries on for another lap at least ….. Last Sunday saw Han and I once again waking up with the pre-dawn calling of birds, as the sun was slowing rising up from its nightly slumber to bathe the countryside between Oxford and Aylesbury with its warming glows. Han and I were up and changed, ready for our first long distance race since I had competed in Guatemala over a year ago, and were trundling along to a small town called Wendover just south of Aylesbury. We had both entered into the Trailscape Wendover full marathon, a 4 part running series that operates a 10km, half and full marathon distance trail race series through the winter months in England. Han, being the organised girl she is, had entered months ago in the full marathon distance, where as I on the other hand had pondered whether to race at all; I had a korfball tournament the next day competing for Wales and wanted some form of freshness for that. When I finally made my mind up to enter the half distance, I logged on only to see that it was sold out, and when looking down the distance ladder, also saw...

A New Chapter Begins

As we left the beaches and volcanoes of Southern Nicaragua our next stop was to visit the two colonial towns of Granada and Leon. After the colonial history burst we planned to visit the highlands of Nicaragua, to a town called Esteli, and thus complete our set of the travelling hotpot of altitudes, climates and adventure. Although a very much subconscious decision at the time, in hindsight it was evident that we were searching. Searching for what, we weren’t sure; some energy, some drive to carry on, a rise out of a travelling slump that we found ourselves in, some passion and excitement at the wonderful cultures and views that we were experiencing. We had left Costa Rica a mere 8 days ago before entering the cobbled streets of Granada, but something in us had changed. We were tired. Tired both mentally and physically. The gregarious imposing churches were no longer exciting, intriguing or gregariously imposing. The lakes, volcanoes, hills, town squares, museums, local food, beers, cultures and people were either becoming common place or annoying. We didn’t have the enthusiasm or drive that we started out with, the enthusiasm or drive that bought us to these far off magical lands, the enthusiasm or drive to get excited about the next city or town. We wanted to give these amazing places more of our time and passion, but were finding it increasingly hard to find that energy as easily as waking up and being enthused about the day ahead. We were in the travelling blues! I’d been in them before, seen them before in other people, experienced them first hand; this weird phenomenon that around the three to four month mark of a long trip backpackers loose the focus and wonder what they are doing. Some of the time people come out of them; sometimes they don’t and leave early, other times people carry on in vain attempts to find the lost passion that they had when they first jumped off the initial plane into the adventure that awaited them. We knew we had to do something and spent a few nights over a few beers talking about what we personally wanted over the next 2-3 months. Our plans changed almost hourly, some purely through hypothetical conversations, some more defined and purposeful like trying to buy bus tickets to Panama, and others through research with twenty different flight prices and times open on the laptop. What did we want? We came to two conclusions. Firstly that we needed a change; be that in culture, lifestyle, or continent, and secondly that we needed an end date. We realised mentally we needed a stop point, not a vague open-ended season that we might be home, but a flight booked home, or at least to some next stage in our journey. We battled these inner demons for a wile before coming to the conclusion that travelling through Central America was coming to an end for us. With my mum and uncle arriving into Mexico for a holiday we used that as a date to meet up with them, and then devised extraordinary plans afterwards of myself flying to New Zealand then onto Vancouver to see my sister and friends respectively, with Han flying to Tel Aviv to visit a friend who had moved there previously and she hadn’t seen for a while, before both meeting back up in the UK near the end of February. Suddenly our journey to far away lands sprang back to life. We had an end point, a focus, a drive, a goal to work towards; the grass started to grew greener on our side of the fence, the sun was not a hot sweat inducing annoyance, but a warmth giving ball of energy, and we were once again motivated, intoxicated with excitement of what was to come and what had come to pass. We made future plans...

Nicaragua – The Beginning

Nicaragua, the largest of the countries in the Central American isthmuses, a very much up and coming destination for backpackers and holiday tourists, is often cited in magazines and websites as a top holiday destination to discover and explore. It was a renewed sense of adventure that we passed through customs and border control relatively hassle free, jumped on a bus after shoving off insistent taxi drivers, and made our way to San Juan Del Sur. Zipping past kilometres of wind farms that had been constructed in the last couple of years as part of the governments promise to decrease air pollution, we passed the hour happily scenery and people watching from our old American yellow school bus. We were heading North along the Pan American Highway with views of two majestic volcanoes on our right, with the Pacific ocean somewhere in the unseeing distance on our left making our way to Rivas, a city where we were to change buses for another smaller local bus to our final destination. After jumping off the bus and walking to the other bus station, we were, as usual, harassed by a host of taxi drivers who had dollar signs in their eyes as they saw another two gringo’s. We had read that often it can be cheaper if you get four of you in a taxi from Rivas to San Juan Del Sur, so we bartered and negotiated a price that we were willing to pay for two of us. Sure it was more than two bus rides would have been, but it would be direct to our hostel and a lot more convenient and comfy. Being surprised by one taxi driver who seemed considerably cheaper than everyone else, we checked, double checked and triple checked the price and destination, but he seemed to be sticking to the low monetary figure, and we figured that he just wanted the business. Move forward 5 minutes and you would have seen me leaning out of a taxi car door as it trundled along a busy street, slowly but perceptively moving into barren areas, shouting at the taxi driver to stop and causing a commotion, as Han fretted over a large knife the taxi driver had just displayed on the seat next to him. Magically and amazingly the price had just doubled as soon as we made about 100m from taxi rank that we were understandably unwilling to pay. Shouting in our pigeon Spanish that we wanted to get a bus and let us out, it was with nervous requests that the taxi driver got out and opened the boot for us to get our bags. We walked back the 300m to the bus station; we were surprisingly calm and serene about the whole situation. If we had managed to get to more desolate areas a couple of minutes further down the road, things might have been different, but opening the door and shouting whilst still in relative busy streets seemed to have sorted out the situation and 10 minutes later we were on a bus to San Juan Del Sur reading the guide books about the up-and-coming surfer beach town. Over our two nights at this black hole of a down under backpacker area; Aussies seemed to converge on the party driven “Funday Sunday” town to never escape and be lost in an eternal struggle of finding themselves on a bus out of there but not missing the next big party, we stayed at a hostel with an amazing infinity pool overlooking the ocean that was renowned for parties, as well as a downtown sandy floored type A backpacker abode. The main highlight though was the main reason that we wanted to visit the area, the Olive Ridley Turtles and their arribadas. In only 7 places over the world a phenomenon known as an arribada happens; thousands upon thousands of turtles converge on...