Category Archives: WordPress

Migrate Expression Engine to WordPress

I was recently asked to migrate an Expression Engine install over to WordPress, naively I said yes and thought “there’ll be an app for that”. There are a bunch of blog posts about it, all which make you do crazy amounts of things to get it work and I don’t know anything about Expression Engine so the best thing to do was a database export/import.

The code I’ve created below uses a good amount of custom fields, both in EE ( i think ) and in WP to manage the data in a logical way, but if you have half an idea of what you are doing you should be able to read the code and figure it out :)

[php]
## SELECT THE WEBLOGS FROM EE
$exp_q = mysql_query(“SELECT * FROM `exp_weblog_data` WHERE `weblog_id` = ‘4’ ORDER BY `entry_id` ASC”);
while($exp = mysql_fetch_array($exp_q)):

## SELECT THE EXTRA DATA FROM THIS OTHER FIELD
$exp_extra_q = mysql_query(“SELECT * FROM `exp_weblog_titles` WHERE `entry_id` = ‘”.$exp[‘entry_id’].”‘ AND `weblog_id` = ‘4’”);
$exp_extra = mysql_fetch_array($exp_extra_q);

// ORDER ALL THE FIELDS
// $exp[‘field_id_5’] // EVENT SUMMARY
// $exp[‘field_id_6’] // EVENT DESCRIPTION
// $exp[‘field_id_7’] // EVENT LOCATION
// $exp[‘field_id_10’] // EVENT IMAGE
// $exp[‘field_id_11’] // EVENT TIME
// $exp[‘field_id_12’] // EVENT IMAGE CAPTION

// $exp_extra[‘title’] // TITLE
// $exp_extra[‘url_title’] // URL – i don’t think ill use this though… well no, i might as well, saves some processing work.

## PULL OUT THE FEATURED IMAGE FILE NAME
$ft_img = explode(‘1}’, $exp[‘field_id_10’]);
$ft_img = explode(‘”‘, $ft_img[1]);

## FORMAT THE LOCATION LINK
$link_name = explode(‘”‘, $exp[‘field_id_7’]);
$link_name = explode(‘”‘, $link_name[1]);
$link = explode(‘”:’, $exp[‘field_id_7’]);
$link = explode(‘,’, $link[1]);
$remain = explode(‘,’, $exp[‘field_id_7’]);

////////
$location = ‘‘.$link_name[0].’, ‘.$remain[1].”;
////////

## INSERT POST INTO WORDPRESS
mysql_query(“INSERT INTO `wp_posts` (
`post_author`,
`post_date`,
`post_date_gmt`,
`post_content`,
`post_title`,
`post_excerpt`,
`post_status`,
`comment_status`,
`ping_status`,
`post_password`,
`post_name`,
`to_ping`,
`pinged`,
`post_modified`,
`post_modified_gmt`,
`post_content_filtered`,
`post_parent`,
`guid`,
`menu_order`,
`post_type`,
`post_mime_type`,
`comment_count`) VALUES(
‘1’,
‘2012-09-05 20:15:14’,
‘2012-09-05 20:15:14’,
‘”.$exp[‘field_id_6’].”‘,
‘”.$exp_extra[‘title’].”‘,
‘”.$exp[‘field_id_5’].”‘,
‘publish’,
‘open’,
‘open’,
”,
‘”.$exp_extra[‘url_title’].”‘,
”,
”,
‘2012-09-05 20:15:14’,
‘2012-09-05 20:15:14’,
”,
‘0’,
”,
‘0’,
‘events’,
”,
‘0’
)”);

## SAVE THIS
$POST_ID = mysql_insert_id();

## INSERT THE CUSTOM FIELDS
mysql_query(“INSERT INTO `wp_postmeta` (
`post_id`,
`meta_key`,
`meta_value`) VALUES (
‘”.$POST_ID.”‘,
‘event_location’,
‘”.$location.”‘)”);

mysql_query(“INSERT INTO `wp_postmeta` (
`post_id`,
`meta_key`,
`meta_value`) VALUES (
‘”.$POST_ID.”‘,
‘_event_location’,
‘field_5047b43381d78’)”);

mysql_query(“INSERT INTO `wp_postmeta` (
`post_id`,
`meta_key`,
`meta_value`) VALUES (
‘”.$POST_ID.”‘,
‘event_time’,
‘”.$exp[‘field_id_11’].”‘)”);

mysql_query(“INSERT INTO `wp_postmeta` (
`post_id`,
`meta_key`,
`meta_value`) VALUES (
‘”.$POST_ID.”‘,
‘_event_time’,
‘field_5047b433821a7’)”);

## INSERT IMAGE INTO POSTS FEATURED IMAGE
mysql_query(“INSERT INTO `wp_posts` (
`post_author`,
`post_date`,
`post_date_gmt`,
`post_content`,
`post_title`,
`post_excerpt`,
`post_status`,
`comment_status`,
`ping_status`,
`post_password`,
`post_name`,
`to_ping`,
`pinged`,
`post_modified`,
`post_modified_gmt`,
`post_content_filtered`,
`post_parent`,
`guid`,
`menu_order`,
`post_type`,
`post_mime_type`,
`comment_count`) VALUES(
‘1’,
‘2012-09-05 20:15:14’,
‘2012-09-05 20:15:14’,
”,
‘”.$exp[‘field_id_12’].”‘,
”,
‘inherit’,
‘open’,
‘open’,
”,
‘”.$exp[‘field_id_12’].”‘,
”,
”,
‘2012-09-05 20:15:14’,
‘2012-09-05 20:15:14’,
”,
‘”.$POST_ID.”‘,
‘http://spin.ecko.cc/wp-content/uploads/2012/09/”.$ft_img[0].”‘,
‘0’,
‘attachment’,
‘image/jpeg’,
‘0’
)”);

## LINK IT TOGETHER IN THE POST_META
mysql_query(“INSERT INTO `wp_postmeta` (
`post_id`,
`meta_key`,
`meta_value`) VALUES(
‘”.$POST_ID.”‘,
‘_wp_attached_file’,
‘2012/09/”.$ft_img[0].”‘)”);

## AND SPIT OUT ONCE DONE….
echo ‘‘.$i.’, —> ‘.$exp_extra[‘title’].’
‘;

endwhile;
[/php]

WordPress for iOS 3.1

20120809-110445 PM.jpg

Matt mentioned these updates in State of the Word 2012 and its just been released. It’s pretty amazing now!

WP Canvas

About this time last year I made a canvas with a QR code on it, it hangs proudly in my office. I had bought two canvases then but only used one. Today I had an idea for the second!

WP Canvas! – It only took 20 minutes to make and I think it turned out well. Thoughts?

WordPress: Custom Category Lists

WordPress has a category list widget which you can use to show all the used categories on your blog, you can even style it via CSS to make it pretty but sometimes designers like to make it hard for you and be all ” no don’t use images, because then we need to scale them for iPhone & iPad retina display, just use a symbols font for that! ” Crazy.

So heres a categories list, just like the widget, but you can style it or change the HTML in any way you like!

[php]
$args = array(‘orderby’ => ‘name’, ‘order’ => ‘ASC’);
$categories = get_categories($args);
foreach($categories as $category) {
echo ‘

  • ) ‘.$category->cat_name.’
  • ‘;
    }
    [/php]

    via Inigo Media

    Alternative to Sessions within WordPress

    Nobody told me that WordPress total jacks up the globals making it near impossible for you to register sessions within WordPress. I tried a couple hacks to enable it via functions.php, I even went as far as ripping out code from the core to get it to work!

    In a Google search I stumbled upon the Transient API – oh lordy, yes!
    So custom sessions aren’t working for me, transients are the next best thing, they are super easy too!

    [php]
    ## STORE TEXT
    set_transient($myvar, ‘text I want to store’, 60*60*12);

    ## RETRIEVE TEXT
    echo get_transient($myvar);

    ## DELETE THE TEXT
    delete_transient($myvar);
    [/php]

    All my troubles seem so far away!