M
M
Michael2015-11-12 22:30:09
WordPress
Michael, 2015-11-12 22:30:09

How to display a post page in Wordpress?

Hello dear experts.
I have the following question
. I have a Wordpress plugin in which I intercept the 404 error and get the URL of the old post based on its address. Then I do the transformations and get a WP_Post object with the right post to display
. Now the question is how can I immediately display this post in the form it should be.
without wp_redirect or other redirects.
The easiest option that I came up with is to do echo wp_remote_fopen(....<permalink post address>...)
But maybe there is a more correct way?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2015-11-16
@1099511627776

In general, it seems to have turned out, the function code looks like this:

function func_404_redirect($query){
  global $wp_query;
  $post = get_post(2);
  $wp_query->queried_object = $post;
  $wp_query->is_single = true;
  $wp_query->is_404 = false;
  $wp_query->queried_object_id = $post->ID;
  $wp_query->post_count = 1;
  $wp_query->current_post=-1;
  $wp_query->posts = array($post);
  
}
add_filter('template_redirect','func_404_redirect');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question