admin管理员组

文章数量:1315827

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.

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.

Share Improve this question edited Apr 19, 2017 at 10:43 WordCent asked Apr 19, 2017 at 9:39 WordCentWordCent 1,8776 gold badges34 silver badges60 bronze badges 4
  • 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 – Jebble Commented Apr 19, 2017 at 10:12
  • WP is installed here → site01. Proof here – WordCent Commented Apr 19, 2017 at 10:44
  • I used your advice given, but it is now showing a blank page. Am I missing anything? – WordCent Commented Apr 19, 2017 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 ;) – Jebble Commented Apr 20, 2017 at 10:22
Add a comment  | 

2 Answers 2

Reset to default 1

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(); ?>

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>

本文标签: Wordpress Search Form IssueMisleading search URLPointing to wrong URL