Skip to content

Instantly share code, notes, and snippets.

@j-mccarthy
Last active August 6, 2018 17:41
Show Gist options
  • Save j-mccarthy/f161b845f0f7d3cadd7cff8ef684dcce to your computer and use it in GitHub Desktop.
Save j-mccarthy/f161b845f0f7d3cadd7cff8ef684dcce to your computer and use it in GitHub Desktop.
/**
* Query used to pull in post data for custom data array
*/
function get_all_events() {
$args = array(
// Type & Status Parameters
'post_type' => 'event',
'post_status' => 'published',
// Order & Orderby Parameters
'order' => 'DESC',
// Pagination Parameters
'posts_per_page' => -1,
// Parameters relating to caching
'no_found_rows' => false,
'cache_results' => true,
'update_post_term_cache' => true,
'update_post_meta_cache' => true,
// Filtering
'facetwp' => true,
);
$query = new WP_Query( $args );
// Following this I use the data in query to build from, adding custom meta data to a custom array
foreach ( $query->posts as $index => $event ) {
$event_data[$index]['post_object'] = $event;
$event_data[$index]['start_time'] = get_post_meta( $event->ID, 'event_data_group_time_date', true );
$event_data[$index]['duration'] = get_post_meta( $event->ID, 'event_data_group_event_duration', true );
$event_data[$index]['location'] = get_post_meta( $event->ID, 'event_data_group_location_address', true );
$event_data[$index]['is_reoccuring'] = get_post_meta( $event->ID, 'event_data_group_is_reoccurring_event', true );
}
// This is returned in the template file.
return $event_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment