I have a custom page in my theme where I am creating a post from a different DB table and I want to then make this display inside wordpress as if it were a normal post. It seems to work most of the time, but randomly it seems that the post is modified after i call get_header() and i cant see why.
I have setup a mod rewrite rule in apache to hit a php file and in here i get the data I need and build the php object. I populate the wordpress post object using this function.
function BuildSimplePost($title, $body)
{
require_once( SITEROOT . '/wp-load.php' );
@$post = new WP_Post();
@$post->ID = -1;
$post->post_parent = 0;
$post->post_title = $title;
$post->post_name = "simple-response";
$post->post_excerpt = substr($body, 0, 100);
$post->comment_status = "closed";
$post->ping_status = "closed";
$post->post_type = "page";
$post->post_content = $body;
return $post;
}
Once the post is sorted I then push this post into the wordpress query objects and let the theme do the rest of the work.
$posts = array($post);
$wp_query->posts = $posts;
$wp_query->post_count = count($posts);
$wp_query->found_posts = count($posts);
$wp_query->max_num_pages = 1;
$wp_query->post = $post;
$wp_query->is_404 = 0;
$wp_query->is_singular = 1;
$wp_query->is_single = 1;
$wp_query->page_id = $post->ID;
include get_template_directory()."/external-page.php";
Inside external-page.php
there is nothing weird. It is literally a copy of single.php with some html removed. The issue im having is that when get_header();
is called in this file the post is changed to something else. This then triggers a redirect which brings the user to a different page on the site that is part of wordpress.
Anyone know why the get_header method would be causing a redirect like this?
<head>
tags or some really messed up suff, or like ameta refresh
who knows unless you look. Maybe you see Easter Bunny there? You don't know what you think you know until you actual know it. – ArtisticPhoenixob_start(); get_header(); $content = ob_get_clean();
that will execute the function but capture the output in the buffer, then you will know if there is some content in the header that is doing it or some functionality. It's a process you just got to eliminate things. – ArtisticPhoenix