Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Created March 16, 2012 23:57
Show Gist options
  • Save zanematthew/2053730 to your computer and use it in GitHub Desktop.
Save zanematthew/2053730 to your computer and use it in GitHub Desktop.
BMX RE -- Adding a well structured array of Events.
<?php
/**
* At this point $pages is already a well structured array of solid data,
* which is probally parsed and cleaned. All thats needed from here is
* database insertation. At the moment we're using WordPress, duh. The only
* custom function used here is "add_event_term", which handles some complex
* logic, checking if a term already exists and what not. All other functions
* can be found in the WordPress Codex, http://codex.wordpress.org/
*/
foreach( $pages as $page => $events ) {
foreach( $events as $event ){
$post = array(
'post_title' => $event['title'],
'post_type' => 'bmx-race-event',
'post_status' => 'publish'
);
$post_id = wp_insert_post( $post, true );
if ( is_wp_error( $post_id ) ) {
print_r( $post_id->get_error_message() );
print "\n";
print_r( $post_id->get_error_messages() );
print "\n";
print_r( $post_id->get_error_data() );
return;
} else {
add_event_term( $post_id, $event['city'], 'city' );
add_event_term( $post_id, $event['state'], 'state' );
add_event_term( $post_id, $event['track'], 'track' );
update_post_meta( $post_id, 'bmx_rs_date', $event['date'] );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment