• Hi,

    I’d like to display a different post than the one requested without redirecting the visitor.

    For example: http://www.site.com/title-post1-ID1 displays the content of another post having the ID ID2

    ID2 is chosen using some of my visitor properties. Meta (opengraph, meta, etc) must be changed as well. In fact, that’s the entire post that I want to change.

    A solution consists in replacing the post object on the fly using a plugin, which must be executed before all other plugins and before executing the template single.php.

    /* my plugin */
    
    function my_post_action($post_object)
    {
     if (/* my conditions */)
         {
          $post_object = get_post(/* a new post with ID2 */);
        }
        return $post_object;
    }
    
    add_action( 'the_post', 'my_post_action',0 );

    This plugin doesn’t work. Questions:

    – is it possible to modify the post object with such an action?
    – before all plugins and template?
    – how to run this action for the current post and not for the posts related in the single page widgets (related post, etc)

    I’ve been trying for days. Thank for your help.

    Tom

  • The topic ‘Modify the entire post without redirect – swap post plugin’ is closed to new replies.