I have two pages on my Wordpress site:
mysite.com/?p=100
mysite.com/?p=200
I think I should be able to hook into Wordpress' actions somewhere and re-query the post, so that content for mysite.com/?p=200
would be displayed on the page mysite.com/?p=100
Based on feedback from the first answer, I think it would need to look something like this:
add_action( 'pre_get_posts', 'wpse35832_pre_get_posts' );
function wpse35832_pre_get_posts( $query ){
$pid = '';
if( ! empty( $query->query_vars['page_id'] ) )
{
$pid = $query->query_vars['page_id'];
}
elseif( ! empty( $query->queried_object->ID ))
{
$pid = $query->queried_object->ID;
}
if($pid == '100'){
$query->query_vars['page_id'] = 200;
}
return $query;
}
And actually that function does work - but with one caveat: If I use pretty permalinks (mysite.com/name-of-page/
), the title of the page is for the original post. However if permalinks are in the query variable style, everything seems to work fine.
What am I doing wrong, and how can I fix it? I tried unset($query->queried_object
so that it would need to be re-queried, and doing that causes a redirect back to the original page.
Basically I'd like the whole webpage that is rendered to be exactly the same as it would be for the other post, including title tag, post title, and post content, and so I'm trying to hook in early enough to make that happen.
I realize I could create a custom page template, something like post-200.php
and inside that use the query_posts
function and display content. This is not what I'm trying to do though.
I admit this would serve no practical purpose on most blogs, but I think it is possible and I hope you guys can give me some help with doing it.