Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<?
// init action
add_rewrite_rule(
'courses/view/(\w+)/?$',
'index.php?course_id=$matches[1]',
'top'
);
// template_redirect action
if ( get_query_var( 'course_id' ) ) {
$wp_query->is_404 = false;
status_header( '200' );
add_filter( 'template_include', function() {
return get_template_directory() . '/courses/course_detail.php';
});
}
// functions.php
function get_course_detail() {
$course_id = get_query_var('course_id');
$url = DATA_API_URL."/courses/view/$course_id/?format=json";
$result = wp_remote_get( $url );
$response = wp_remote_retrieve_body( $result );
return json_decode($response);
}
// course_detail.php
$course = get_course_detail();
..
echo $course->title;
..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment