Vagrant WordPress

Vagrants is a portable development environments which can be used as part of your web development workflow.
Varying Vagrant Vagrants or vvv is Vagrant configuration focused on WordPress development.
In this screen-cast I  set up a Vagrant WordPress development environment using Varying Vagrant Vagrants. It was pretty straight forward to do. The only thing I assume is that you have Git set already. The biggest headache I encounter was the fact that Varying Vagrant Vagrants is quite possibly the worst name ever.

Setting up a Vagrant WordPress

Vagrant and Varying Vagrant Vagrants looks promising. I’m not sure if I will drop my xamp work flow straight away but I will certainly be keeping an eye on it.

Vintage textile patterns

Here is a selection of 10 Hi-res images for you to feast upon. 10 lovely vintage textile patterns. Use as a whole or enlarge to expose the detail of the fabric. Click on the link below each preview to download or download all the images in one zip file at the bottom of the post.

WordPress $wpdb basics

Access WordPress Database

Starship $wpdb

Recently I’ve been adapting a plug-in to suit my needs and for the first time, trying to write something that interacts with the wordpress database, step up wpdb class!

The WPDB Class – Make it Global

To use the wpdb class we need to access a global variable $wpdb which is simple enough, but what you’ve got to remember is that it needs to be globalized before you use it in your custom function: –

global $wpdb;

Once that’s in place you are free to use it to perform SQL queries and function on your database.

The first thing I needed to do was to query the “commentmeta” table in the database, and save the results for later use: –

$comment_meta = $wpdb->get_results( "SELECT mydata FROM mytable WHERE mycondition = 'myvalue' ");

The above code uses ‘get_results’ to query the database and loads in to the the variable $comment_meta so it can be used in a ‘foreach’ loop later. Now I wanted to grab the meta_key, meta_value from table ‘commentmeta’ that was named ‘wp_1_commentmeta’. I could have put that value into the query but if I want to use the function on a different site on a wordpress network I’m not going to know the database prefix so I can use $wpdb to replace it: –

$comment_meta = $wpdb->get_results( "SELECT meta_key, meta_value FROM wpdb->commentmeta ");

That way I can use the query in a function on any wordpress blog and it will always knows what table to look at.

It’s an Object by default

One last thing to remember is that the results are an object so you can access the like this: –

foreach ( $comment_meta as $comment_meta_data )
echo $comment_meta_data->meta_key
echo '< br />'
echo $comment_meta_data->meta_value

And that’s what I wanted but if you want something different like an array then you can use OBJECT_K for an associative array of row objects, using first column’s values as keys, ARRAY_A for a numerically indexed array of associative arrays, using column names as keys or ARRAY_N for a numerically indexed array of numerically indexed arrays like this: –

$comment_meta = $wpdb->get_results( "SELECT meta_key, meta_value FROM wpdb->commentmeta", ARRAY_N );

for more information on the wpdb class check out the wordpress codex