0

The website I am working on can list restaurants and we can rate them. Currently, I'm developing a multi criteria search to find the good one.

I created a custom HTML form with XYZ Html (plugin) and I added the snippets to a page:

the search page (1) the search page (2)

I put the following code in the functions.php file (wp-content/themes/auberge) to intercept the submit:

function recherche_multi_critere() {
    if ( $_POST['nom'] != NULL ) {
        // ...
    }
}    
add_action( 'template_redirect', 'recherche_multi_critere' );

But when I'm here, I don't know how to create a custom page with the data. For example, I want to list all the restaurants that match the search as links. What can I do ?

  • WP Version : 4.3.1
  • PHP/MySQL Version : 5.5.12/5.6.17
  • Theme : Auberge
  • Extensions : bbpress, Beaver Builder Plugin (Lite Version), Clean and Simple Contact Form, Display Posts Shortcode, Header and Footer, Insert HTML Snippet, Insert PHP, Jetpack par WordPress.com, Livre d'or Gwolle (Gwolle GuestBook), PHP Code for posts, Post Meta Inspector, Ultimate Member, WordPress Reviews, WordPress Reviews Submit, WP Google Maps
0

1 Answer 1

0

First, your code attempts to use $_POST['nom'] whether the value is set or not. You are generating non-fatal "Undefined index" warning every time that runs. Clean that up and use !empty($_POST['nom']) instead of $_POST['nom']!=NULL.

With template_redirect you'd want to redirect to an existing page, something like the following from another answer:

function redirect_cat_wpse_207298() {
  if (is_category()) {
    global $post;
    wp_safe_redirect(get_permalink($post->ID));
    die;
  }
}
add_action('template_redirect','redirect_cat_wpse_207298');

Since you say "create a page", I am guessing there is no page to redirect to, so you probably want template_include instead. Something like:

function recherche_multi_critere() {
  if(!empty($_POST['nom'])) {
    get_header();
    var_dump($_POST['nom']);
    get_footer();
  }
}
add_action('template_include', 'recherche_multi_critere');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.