Surprise pickup by Uncle Andy at 12:00 back to his house for Jack & Cokes.


Pub!
Just another WordPress developer
Surprise pickup by Uncle Andy at 12:00 back to his house for Jack & Cokes.


Pub!
Its always the little things I forget and today it was how to list out categories based on a custom post type (or not, really). Really, its very simple
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 :)
## 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 = '<a href="'.$link[0].'" target="_blank">'.$link_name[0].'</a>, '.$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 '<strong>'.$i.',</strong> ---> '.$exp_extra['title'].'<br />';
endwhile;

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

my little boy starts school on Tuesday. Epic times.