0

Generally,

We put <?php get_search_form(); ?> in the header where we desire the search form, and then later we put the custom code for HTML in searchform.php.

This is the whole HTML from where I am trying to create an HTML template.

This is the Portion of an HTML

<li><input class="search" type="search" placeholder="Search"></li>

that was supposed to be converted into an working wordpress search.

However, I put this whole form modified a little bit with my CSS's classes →

        <form action="/" method="get">
            <li>
                <input class="search" type="search" placeholder="Search" type="text" name="s" id="search" value="<?php the_search_query(); ?>">
            </li>
        </form>

THE PROBLEM → Misleading search URL. Suppose my search string is "ok"

The search URL anticipated to be generated is →

right but it generates →

wrong.

Live WP Site here.

  • What if you change action="/" to action="<?php echo esc_url( home_url( '/' ) ); ?>"? WordPress seems to not be actually installed in site01? Make sure the settings are correct in wp-admin – Jeffrey von Grumbkow Apr 19 '17 at 10:12
  • WP is installed here → site01. Proof here – The WP Intermediate Apr 19 '17 at 10:44
  • I used your advice given, but it is now showing a blank page. Am I missing anything? – The WP Intermediate Apr 19 '17 at 12:58
  • Well your search form is now pointing towards the correct url. Now you need a search.php page that loops through the found results ;) – Jeffrey von Grumbkow Apr 20 '17 at 10:22
0

Try this form based on your code:

<form action="<?php echo esc_url(home_url()); ?>" method="get">
  <li>
    <input class="search" type="text" name="s" id="s" 
           placeholder="Search" value="<?php the_search_query(); ?>">
  </li>
</form>
| improve this answer | |
0

Below you can find a template for displaying Search Results pages. Add the code to your search.php file. If you have installed the WP-PageNavi plugin then you'll see the pagination if the search result has more than 10 items.

<?php
/**
 * The template for displaying Search Results pages.
*/
get_header();
?>

<h2><?php printf( __( 'Search Results for: %s', 'themedomain' ), '<strong>"' . get_search_query() . '"</strong>' ); ?></h2> <div class="posts"> <?php global $paged; $s = $_GET['s']; $post_types = array('post', 'page'); $args=array( 'post_type' => $post_types, 'post_status' => 'publish', 's' => $s, 'orderby' => 'date', 'order' => 'desc', 'posts_per_page' => 10, 'paged' => $paged ); $wp_query = new WP_Query($args); if ($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?> <!-- post-box --> <article class="post-box"> <div class="meta"> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> <p><?php _e('Posted by','themedomain');?> <?php if (!get_the_author_meta('first_name') && !get_the_author_meta('last_name')) { the_author_posts_link(); } else { echo '<a href="'.get_author_posts_url(get_the_author_meta('ID')).'">'.get_the_author_meta('first_name').' '.get_the_author_meta('last_name').'</a>'; } ?> <?php _e('&middot; on','themedomain');?> <?php echo get_the_time('F d, Y'); ?> <?php _e('&middot; in','themedomain');?> <?php the_category(', ') ?> <?php _e('&middot; with','themedomain');?> <?php comments_popup_link(__('0 Comments', 'themedomain'),__('1 Comment', 'themedomain'), __('% Comments', 'themedomain')); ?></p> </div> <?php the_excerpt(); ?> <p><a href="<?php the_permalink(); ?>"><?php _e('Continue Reading &rarr;','themedomain'); ?></a></p> </article> <?php endwhile; endif; ?> </div> <!-- paging --> <div class="paging"> <ul> <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?> </ul> </div>

<?php get_footer(); ?>

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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