Created
May 25, 2015 08:20
-
-
Save Dimasmagadan/859bae66f3f1ef803a15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function os_rewrite_rules(){ | |
$options = get_option( 'os_ub_settings', array( 'os_ub_text_slug' => 'company' ) ); | |
$slug = $options['os_ub_text_slug']; | |
$cat_slug = $options['os_ub_cat_slug']; | |
add_rewrite_rule('^'.$slug.'/add/?','index.php?page_id=os_ub_add_page','top'); | |
// dev | |
// flush_rewrite_rules( true ); | |
} | |
add_action( 'init', 'os_rewrite_rules', 0 ); | |
add_filter('the_posts', 'os_endpoint_page' ); | |
function os_endpoint_page($posts){ | |
global $wp,$wp_query; | |
$page_slug = 'os_ub_add_page'; | |
//check if user is requesting our fake page | |
// if( count($posts) == 0 && (strtolower($wp->request) == $page_slug || $wp->query_vars['page_id'] == $page_slug)){ | |
if( isset($wp->query_vars['page_id']) && $wp->query_vars['page_id'] == $page_slug ){ | |
$options = get_option( 'os_ub_settings', array( 'os_ub_text_slug' => 'company', 'os_ub_add_page_ID' => 6 ) ); | |
$slug = $options['os_ub_text_slug']; | |
$add_page_ID = $options['os_ub_add_page_ID']; | |
$page = get_post( $add_page_ID ); | |
//create a fake post | |
$post = new stdClass; | |
$post->post_author = $page->post_author; | |
$post->post_name = '/'.$slug.'/add/' ; | |
// $post->post_name = $page_slug; | |
$post->guid = site_url('/'.$slug.'/add/' ); | |
$post->post_title = $page->post_title; | |
//put your custom content here | |
$post->post_content = $page->post_content; | |
$post->ID = $page->ID; | |
// $post->post_status = $page->post_status; | |
$post->post_status = 'static'; | |
$post->comment_status = $page->comment_status; | |
$post->ping_status = $page->ping_status; | |
$post->comment_count = $page->comment_count; | |
// $post->post_date = current_time('mysql'); | |
$post->post_date = $page->post_date; | |
$post->post_date_gmt = $page->post_date_gmt; | |
$posts = NULL; | |
$posts[] = $post; | |
$wp_query->is_page = true; | |
$wp_query->is_singular = true; | |
$wp_query->is_home = false; | |
$wp_query->is_archive = false; | |
$wp_query->is_category = false; | |
unset($wp_query->query["error"]); | |
$wp_query->query_vars["error"]=""; | |
$wp_query->is_404 = false; | |
} | |
return $posts; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment