When a comment is stored in the WordPress database, the identifier of the post (or page) associated with the comment is also stored.
The problem is that you are trying to save comments using WordPress, but for a page that she actually does not know about.
So, how about creating a WordPress page for every real page, but just as a presentation, so your real pages and WordPress have a common foundation for working with each other.
So the plan is here:
- Download WordPress in the background on each of the real pages.
- See if there is a WordPress page view for a "real" page
- If itβs not, create it, then there
- Trick WordPress, thinking we are really looking at the presentation
- Continue to use all the WP features and template tags as usual.
This code should be somewhere at the beginning of the template file used to render your "real" pages;
include ('../path/to/wp-load.php'); // remove query string from request $request = preg_replace('#\?.*$#', '', $_SERVER['REQUEST_URI']); // try and get the page name from the URI preg_match('#podpages/([a-z0-9_-]+)#', $matches); if ($matches && isset($matches[1])) { $pagename = $matches[1]; // try and find the WP representation page $query = new WP_Query(array('pagename' => $pagename)); if (!$query->have_posts()) { // no WP page exists yet, so create one $id = wp_insert_post(array( 'post_title' => $pagename, 'post_type' => 'page', 'post_status' => 'publish', 'post_name' => $pagename )); if (!$id) do_something(); // something went wrong } // this sets up the main WordPress query // from now on, WordPress thinks you're viewing the representation page }
UPDATE
I canβt believe that I was so stupid. The following should replace the current code inside the external if ;
// try and find the WP representation page - post_type IS required $query = new WP_Query(array('name' => $pagename, 'post_type' => 'page')); if (!$query->have_posts()) { // no WP page exists yet, so create one $id = wp_insert_post(array( 'post_title' => $pagename, 'post_type' => 'page', 'post_status' => 'publish', 'post_name' => $pagename, 'post_author' => 1, // failsafe 'post_content' => 'wp_insert_post needs content to complete' )); } // this sets up the main WordPress query // from now on, WordPress thinks you're viewing the representation page // post_type is a must! wp(array('name' => $pagename, 'post_type' => 'page')); // set up post the_post();
PS I think that using query_var name more than pagename better suited - it requests slug, not the pool 'path'.
You will also need to put the input inside the form with the name redirect_to and the URL value that you want to redirect, or , filter the redirection using the function connected to comment_post_redirect , returning the correct URL.