WordPress.org

Ready to get started?Download WordPress

Forums

From php code, how do I send the visitor to a specific page? (2 posts)

  1. RonStrilaeff
    Member
    Posted 2 years ago #

    I must have a mis-conception because what I'm tryin to do seems like it should be super easy and already built in to WP.

    At a certain point in the execution of a search plugin I'm using, I can tell that nothing is found. So instead of showing a blank content area (like it does now), I would like to show a special page (that I can edit in the wp page editor) with a nice error message and a small photo gallery with links to other interesting posts.

    I was looking at include() and wp_redirect(), but those functions are not designed for that. Can someone throw me a crumb? I expect it to work just like someone clicked on a menu item that took them to that page, but without the click, just automatically take them there.

    Thanks, Ron

  2. RonStrilaeff
    Member
    Posted 2 years ago #

    Ok, I'm pretty sure I'm breaking some rules here since I'm assuming WordPress will "cleanup" whatever it was doing at the time. But this little snippet works by making an immediate exit from wherever to just show my "not-found" custom page.

    $homeurl = home_url('/not-found/');
    echo "<script>window.location = '$homeurl'</script>";

    If I was designing a proper search plugin, I would have done this a bit more elegantly, handling the possibility of empty results and maybe even having the failover "not-found" page name configurable. But as it was, all the visitors would see was a blank page with no explanation. Now it's WAY better and I can make that page do anything I want, even using a custom page template.

    I'm open to learn if someone cares to suggest a better way to do this.

    Thanks, Ron

Topic Closed

This topic has been closed to new replies.

About this Topic