I posted earlier about speaking at WordCamp Cape Town about using WordPress as a Development Framework, here is the video for your viewing pleasure!
I posted earlier about speaking at WordCamp Cape Town about using WordPress as a Development Framework, here is the video for your viewing pleasure!
I gave a talk at WordCamp Cape Town yesterday about using WordPress as a Development Framework for building web applications. Here’s my slides, I’ll update this post shortly with a bit more information – like the links to the video clip and code snippets.
I will be speaking at WordCamp Cape Town this year, and I’m pretty excited
It will be my second WordCamp presentation after last years WordCamp Spain in Barcelona. I’ll be showing off some of the more advanced concepts of WordPress and trying to get rid of a mindset that WordPress is just a blogging engine – I believe that it’s good enough to be used as a fully fledged development framework for everything from a basic website to a full on web application. I’ll post my slides and the code that I use in the talk here as always
If you’ve ever delved into the WP core you’ll find some little items that are quite unknown. Take tax_query for example; most developers are aware of the standard options: ‘taxonomy’ ‘field’ and ‘terms’ but did you know there is an ‘include_children’ option? This returns only direct parent matches for the taxonomy terms specified – in other words, no child terms if you are using hierarchies. This is pretty straightforward for custom queries, but what about archive pages? Here’s a filter for that:
// Custom Taxonomy Page Filter
add_action('pre_get_posts', 'my_taxonomy_children_filter' );
function my_taxonomy_children_filter( $query ) {
global $wp_query;
if ($query->is_tax) {
$modded_tax_query = $query->tax_query;
$filter_tax = $modded_tax_query->queries[0]['taxonomy'];
$filter_terms = $modded_tax_query->queries[0]['terms'];
$filter_field = $modded_tax_query->queries[0]['field'];
$query->set('tax_query', array(array(
'taxonomy' => $filter_tax,
'field' => $filter_field,
'terms' => $filter_terms,
'include_children' => false
))
);
$query->parse_query();
}
return $query;
}
Works pretty well for me. Pop that into your functions.php and it should do the trick
Let me know if it doesn’t for you!
I’ve been working on a performance issue with a for loop in a theme in WordPress for the past week, in particular trying to get the number of queries down. The homepage was executing around 10000 queries to the DB, which while it executed each query quickly due to the SQL being optimized, was ultimately slowing the site down. So after several pointers from various people, I spend some time with the code and managed to get it down to 290 queries after optimizing the loop structure. To do this I used 2 plugins that were a MASSIVE help:
Debug Bar and Debug bar Console
If you are a WordPress developer, I highly recommend using these as they really make the debugging process far easier due to their comprehensive info panels that you can switch on and off.
Sidenote: If you are using foreach to loop through an array and you only want a cross section of the results, try using the array_slice function instead of using a counter variable.
Lately there have been a couple of posts in the WordPress community about DB queries and the amount of calls that are made per page. While that clearly has merit and I’m by no means saying ignore it, there’s been very little focus on the actual DB queries themselves. No offense to anyone, but if you are going to focus on the number of DB calls instead of first optimizing your SQL – then either you know very little about development, or have never built a large scale web application.
So, if you have queries that have any kind of JOIN in them, I would suggest restructuring those as a first port of call. ONLY once you’ve done that should you move onto optimizing the code. I hit a performance related issue this past week and while it ended up having to do with the amount of DB calls, the problem wasn’t the SQL queries in that case but as my general rule of thumb I checked them first. That allowed me to figure out that the problem was in the code.
What do you think about optimization?
Got an email from AppSumo today for a special on the Cart66 e-commerce and membership plugin for WordPress. Only $45 for the next 14 hours! That’s basically half price. If you want it, now is the time to buy! Click the title link above to get the special!
Cool interview with Adii from WooThemes by Charl Norman from Bandwidth Blog.