WordPress: Post abstraction

At Metro we use WordPress but more and more logic is shifting to web services (so that we can order content algorithmically).

Currently that means we need to write different view logic depending on whether data comes from the WordPress database or from a web service.

The solution? Abstract it. For example.

Data from WP_Query

// WP_Query specific code
$the_query = new WP_Query( $args );
$ds = Metro_Data_Source( $the_query );

// Abstracted code
echo $ds->get_the_ID();

Data from a web service

// Web service specific code
$ds = Metro_Data_Source( 'http://api.metro.co.uk/blah', CACHE_TIME );

// Abstracted code
echo $ds->get_the_ID();

Will probably get complicated with things like images though…

Leave a Reply

%d bloggers like this: