Search Form not working on Wordpress - wordpress

I am having problems with the search form on wordpress. When i try and search any term at all it gives me the "Sorry, no posts match your query" response (I have "Search Everything" plugin installed too). I am using a child theme. so I tried to change the code in the child search.php (copied it to the child) and also created a searchform.php in the child. Here is the code from both of those that I am currently using:
SEARCH.PHP:
> <?php
/**
* Search Template
*
* The search template is used to display search results from the native WordPress search.
*
* If no search results are found, the user is assisted in refining their search query in
* an attempt to produce an appropriate search results set for the user's search query.
*
* #package WooFramework
* #subpackage Template
*/
get_header();
global $woo_options;
?>
<!-- #content Starts -->
<?php woo_content_before(); ?>
<div id="content" class="col-full">
<div id="main-sidebar-container">
<!-- #main Starts -->
<?php woo_main_before(); ?>
<section id="main" class="col-left">
<header class="page-header">
<h1 class="page-title"><?php printf( __( 'Search Results for: %s', '' ), get_search_query() ); ?></h1>
</header><!-- .page-header -->
<?php
$query = new WP_Query( array( 's' => get_query_var('s')) );
// The Loop
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
}
?>
<?php var_dump($the_query) ?>
</section><!-- /#main -->
<?php get_sidebar(); ?>
</div><!-- /#main-sidebar-container -->
<?php get_sidebar( 'alt' ); ?>
</div><!-- /#content -->
<?php woo_content_after(); ?>
<?php get_footer(); ?>
SEARCHFORM.PHP (I got from the twenty twelve theme):
<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label for="s" class="assistive-text"><?php _e( 'Search', 'twentyeleven' ); ?></label>
<input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
<input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
</form>
I have tried different code for the searchform.php too such as:
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
<label class="hidden" for="s"><?php _e('Search:'); ?></label>
<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="GO" />
</form>
and
<form role="search" method="get" id="searchform" class="searchform" action="<?php esc_url( home_url( '/' )); ?>">
<div>
<label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
<input type="text" value="<?php get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="<?php esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
</form>
and
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<label>
<span class="screen-reader-text">Search for:</span>
<input type="search" class="search-field" placeholder="Search …" value="" name="s" title="Search for:" />
</label>
<input type="submit" class="search-submit" value="Search" />
</form>
But still nothing. When it searches, this is what i get in the url:
http://www.energyhealing.directory/?s=energy&submit=Search
and on the page for that URL it displays:
Search Results for: energy << the title for it
Listed in
Continue Reading << thats a link to nowhere, just comes back to the same page
If someone could just explain to me where I have gone wrong and why, that would be amazing?
Thanks in advance for any help you can give. I look forward to hearing back from you!
Aww ok I see how to post in the question now:
Here is the code from the search.php which just returns the blank page:
<?php
/**
* Search Template
*
* The search template is used to display search results from the native WordPress search.
*
* If no search results are found, the user is assisted in refining their search query in
* an attempt to produce an appropriate search results set for the user's search query.
*
* #package WooFramework
* #subpackage Template
*/
get_header();
global $woo_options;
?>
<!-- #content Starts -->
<?php woo_content_before(); ?>
<div id="content" class="col-full">
<div id="main-sidebar-container">
<!-- #main Starts -->
<?php woo_main_before(); ?>
<section id="main" class="col-left">
<header class="page-header">
<h1 class="page-title"><?php printf( __( 'Search Results for: %s', '' ), get_search_query() ); ?></h1>
</header><!-- .page-header -->
<?php
$query = new WP_Query( array( 's' => get_query_var('s')) );
// The Loop
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
}
?>
</section><!-- /#main -->
<?php get_sidebar(); ?>
</div><!-- /#main-sidebar-container -->
<?php get_sidebar( 'alt' ); ?>
</div><!-- /#content -->
<?php woo_content_after(); ?>
<?php get_footer(); ?>

EDITED (for search.php):
<?php if ( have_posts() ):?>
<ul>
<?php while ( have_posts() ) : the_post();?>
<li><?php the_title();?></li>
<?php endwhile;?>
</ul>
<?php endif;?>
I think the searchform.php is ok, but I don't see a loop anywhere in your search.php
$query = new WP_Query( array( 's' => get_query_var('s')) );
// The Loop
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
}
You need this query to create a loop based on the search.

Related

WordPress search results not displaying

I am using the naked word press theme to build my site with and it all works great apart from when I use the search bar. I type in my search and it takes me to a version of my homepage, but with no content on it.
How do I get my search results to display?
Create a search.php and use this code as an example.
<?php get_header(); ?>
<div id="content">
<?php if (have_posts()) : ?>
<h1>Search Result for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' — '); echo $count . ' '; _e('acapellas'); wp_reset_query(); ?></h1>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</li>
<?php endwhile; endif; ?>
</ul>
</div>
<?php get_footer(); ?>
Make sure your searchform.php complies with Wordpress's standards, heres an example.
<form method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<label>
<span class="screen-reader-text"><?php echo _x( 'Search:', 'label' ) ?></span>
<span>Search</span>
<input type="search" class="search-field" placeholder="Search" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search:', 'label' ) ?>" />
</label>
<button type="submit" class="search-submit" value="<?php echo esc_attr_x( 'Search', 'submit button' ) ?>">
</button>
</form>

Separate registration page in WooCommerce website

Can anybody help me build a separate registration page in WooCommerce instead of displaying it in the my-account page?
In the my-account page I want to display a link which will take the buyer to the registration page.
edit your form-login.php file and seperate the login form and registration form in two different sections say section A and B.
now check for a GET parameter in the page which will define which section to show. By default login will be shown, if parameter is found and is "register", show registration section
if( isset( $_GET['action']) && $_GET['action'] == "register"){
// Section for registration
}else {
// Section for Login form
}
you can provide a link for registration as
register
The Code for form-login.php
is
--- START SECTION ---
<?php
/**
* Login Form
*
* #author WooThemes
* #package WooCommerce/Templates
* #version 2.2.6
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<?php wc_print_notices(); ?>
<?php do_action( 'woocommerce_before_customer_login_form' ); ?>
<?php if ( get_option( 'woocommerce_enable_myaccount_registration' ) === 'yes' ) : ?>
<div class="col2-set" id="customer_login">
<div class="col-1">
<?php endif; ?>
<h2><?php _e( 'Login', 'woocommerce' ); ?></h2>
<form method="post" class="login">
<?php do_action( 'woocommerce_login_form_start' ); ?>
<p class="form-row form-row-wide">
<label for="username"><?php _e( 'Username or email address', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="username" id="username" value="<?php if ( ! empty( $_POST['username'] ) ) echo esc_attr( $_POST['username'] ); ?>" />
</p>
<p class="form-row form-row-wide">
<label for="password"><?php _e( 'Password', 'woocommerce' ); ?> <span class="required">*</span></label>
<input class="input-text" type="password" name="password" id="password" />
</p>
<?php do_action( 'woocommerce_login_form' ); ?>
<p class="form-row">
<?php wp_nonce_field( 'woocommerce-login' ); ?>
<input type="submit" class="button" name="login" value="<?php esc_attr_e( 'Login', 'woocommerce' ); ?>" />
<label for="rememberme" class="inline">
<input name="rememberme" type="checkbox" id="rememberme" value="forever" /> <?php _e( 'Remember me', 'woocommerce' ); ?>
</label>
</p>
<p class="lost_password">
<?php _e( 'Lost your password?', 'woocommerce' ); ?>
</p>
<?php do_action( 'woocommerce_login_form_end' ); ?>
</form>
<?php if ( get_option( 'woocommerce_enable_myaccount_registration' ) === 'yes' ) : ?>
</div>
<div class="col-2">
<h2><?php _e( 'Register', 'woocommerce' ); ?></h2>
<form method="post" class="register">
<?php do_action( 'woocommerce_register_form_start' ); ?>
<?php if ( 'no' === get_option( 'woocommerce_registration_generate_username' ) ) : ?>
<p class="form-row form-row-wide">
<label for="reg_username"><?php _e( 'Username', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="text" class="input-text" name="username" id="reg_username" value="<?php if ( ! empty( $_POST['username'] ) ) echo esc_attr( $_POST['username'] ); ?>" />
</p>
<?php endif; ?>
<p class="form-row form-row-wide">
<label for="reg_email"><?php _e( 'Email address', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="email" class="input-text" name="email" id="reg_email" value="<?php if ( ! empty( $_POST['email'] ) ) echo esc_attr( $_POST['email'] ); ?>" />
</p>
<?php if ( 'no' === get_option( 'woocommerce_registration_generate_password' ) ) : ?>
<p class="form-row form-row-wide">
<label for="reg_password"><?php _e( 'Password', 'woocommerce' ); ?> <span class="required">*</span></label>
<input type="password" class="input-text" name="password" id="reg_password" />
</p>
<?php endif; ?>
<!-- Spam Trap -->
<div style="<?php echo ( ( is_rtl() ) ? 'right' : 'left' ); ?>: -999em; position: absolute;"><label for="trap"><?php _e( 'Anti-spam', 'woocommerce' ); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div>
<?php do_action( 'woocommerce_register_form' ); ?>
<?php do_action( 'register_form' ); ?>
<p class="form-row">
<?php wp_nonce_field( 'woocommerce-register' ); ?>
<input type="submit" class="button" name="register" value="<?php esc_attr_e( 'Register', 'woocommerce' ); ?>" />
</p>
<?php do_action( 'woocommerce_register_form_end' ); ?>
</form>
</div>
</div>
<?php endif; ?>
<?php do_action( 'woocommerce_after_customer_login_form' ); ?>
--- END SECTION ---
Whet can i put this snippet :
--- START SECTION ---
if( isset( $_GET['action']) && $_GET['action'] == "register"){
// Section for registration
}else {
// Section for Login form
}
--- END START
and this URL
--- START SECTION ---
register
--- END SECTION ---
I finally figured out the code to have separate registration and login pages via individual links in the header.
You will need to edit 2 files in your child theme:
functions.php and
form-login.php
I have attached txt files for the code
1) functions.php: You want to create a register link in the header that links to the login page but also sets an action indicating you have clicked register.
So this:
$aux_links_output .= ''. __("Login", "swiftframework") .''. "\n";
becomes this:
$aux_links_output .= ''. __("Login", "swiftframework") .''. "\n";
$aux_links_output .= ''. __("Register", "swiftframework") .''. "\n";
2) form-login.php code:
Here you want to create an if,else statement. If you clicked register then goto register page, else goto login page:
<?php if( isset( $_GET['action']) && $_GET['action'] == "register") : ?>
Section for registration
<?php else : ?>
Section for Login form
<?php endif; ?>
Be careful of the wrappings
Thanks

Wordpress custom post template page/2 loop not working

I have a loop in the sidebar of a custom template and it works perfectly when the page is loaded. The page is -
http://ere.doneready.com/senior-consultants
However the loop (which shows the list of names) does not work when I click the "next" button i.e. this page -
http://ere.doneready.com/senior-consultants/page/2/
Can anyone help? The following is the code I use -
<div id="people-sidebar-content">
<div id="custom-search-form-for-people">
<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div id="custom-search-form-label"><label for="s" class="assistive-text"><?php _e( 'SEARCH' ); ?></label></div>
<span id="search-box-box"><input class="search-box" type="text" name="s" id="s" /></span>
<span id="search-box-button"><input type="image" name="submit" id="searchsubmit" SRC="http://www.doneready.com/ere/wp-content/themes/ere/images/search_button.png" HEIGHT="17" WIDTH="20" BORDER="0" ALT="Submit Form"></span>
</form>
</div>
<div id="people-sidebar-content-usable" class="senior-consultants-active">
<div id="sidebar-for-people">
<a class="directors" href="http:/www.ere.doneready.com/directors/">Directors</a><br />
<a class="finance-admin" href="http:/www.ere.doneready.com/finance-and-admin/">Finance & Admin</a><br />
<a class="senior-consultants" href="http:/www.ere.doneready.com/senior-consultants/">Senior Consultants</a><br />
<div id="actual-people-list">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
'post_type'=>'staff',
'posts_per_page' => 99,
'paged'=>$paged,
'staff_categories'=>'Senior Consultants'
);
$temp1 = $wp_query;
$wp_query= null;
$wp_query = new WP_Query($args);
if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
?>
<div class="actual-people-list-single">
<a href ="<?php the_permalink(); ?>">
<?php echo esc_html( get_post_meta( get_the_ID(), 'staff_short_name', true ) ); ?>
</a>
</div>
<?php
endwhile; endif;
/* PageNavi at Bottom */
$wp_query = null;
$wp_query = $temp1;
wp_reset_query();
?>
</div>
<a class="consultants" href="http:/www.ere.doneready.com/consultants/">Consultants</a><br />
<a class="technical-support" href="http:/www.ere.doneready.com/technical-support/">Technical Support</a>
</div>
</div><!--END PEOPLE-SIDEBAR-CONTENT-USABLE-->
</div><!--END PEOPLE-SIDEBAR-CONTENT-->
</div><!--END CONTENT CONTAINER-->
</div><!--END PAGE-WRAP-->
Welcome to StackOverflow, try to search the archives at least semi-extensively first because many variations of this question exist. Here's a link to my answer to a very similar question, it worked for me, it might work for you:
Making a single page blog in WordPress
Solved. I used a new loop and the code looks like this now -
<div id="people-sidebar-content">
<div id="custom-search-form-for-people">
<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div id="custom-search-form-label"><label for="s" class="assistive-text"><?php _e( 'SEARCH' ); ?></label></div>
<span id="search-box-box"><input class="search-box" type="text" name="s" id="s" /></span>
<span id="search-box-button"><input type="image" name="submit" id="searchsubmit" SRC="http://www.doneready.com/ere/wp-content/themes/ere/images/search_button.png" HEIGHT="17" WIDTH="20" BORDER="0" ALT="Submit Form"></span>
</form>
</div>
<div id="people-sidebar-content-usable" class="senior-consultants-active">
<div id="sidebar-for-people">
<a class="directors" href="http:/www.ere.com.my/directors/">Directors</a><br />
<a class="senior-consultants" href="http:/www.ere.com.my/senior-consultants/">Senior Consultants</a><br />
<div id="actual-people-list">
<?php
$args = array( 'post_type' => 'staff', 'staff_categories'=>'Senior Consultants', 'posts_per_page' => 50 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div class="actual-people-list-single">
<a href ="<?php the_permalink(); ?>">
<?php echo esc_html( get_post_meta( get_the_ID(), 'staff_short_name', true ) ); ?>
</a>
</div>
<?php
endwhile;
?>
<?php
wp_reset_query();
?>
</div>
<a class="consultants" href="http:/www.ere.com.my/consultants/">Consultants</a><br />
<a class="technical-support" href="http:/www.ere.com.my/technical-support/">Technical Support</a>
<a class="finance-admin" href="http:/www.ere.com.my/finance-and-admin/">Finance & Admin</a><br />
</div>

WordPress Search Problems

I have researched this problem and still can't seem to figure out why my search function isn't working on a theme I'm working on. Below is my code that I have for my search.php and my searchform.php files. The search files were hardly modified from a boilerplate, blank WordPress theme. When I search for anything, it returns a 404 error. I have researched search's returning 404's and still can't find the solution. Blow is my code, any help would be greatly appreciated.
searchform.php----------------------------------
<form action="<?php bloginfo('siteurl'); ?>" id="searchform" method="get">
<label for="search"><object data='<?php bloginfo('template_directory');? >/images/input-search.svg'>
<img src='<?php bloginfo('template_directory');?>/images/input-search.png'>
</object></label>
<input type="search" name="search" />
</form>
search.php---------------------------------------
<?php get_header(); ?>
<?php if (have_posts()) : ?>
<h2>Search Results</h2>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>
<div class="entry">
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; ?>
<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
<?php else : ?>
<h2>No posts found.</h2>
<?php endif; ?>
You need to make sure that your search form is enabled in your functions.php file like so:
// ENABLES SEARCH FORM STUFF
function my_search_form( $form ) {
$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
</div>
</form>';
return $form;
}
// ENABLES SEARCH FORM
add_filter( 'get_search_form', 'my_search_form' );
This is the code I use in my themes. Then this would call in my search form:
<?php get_search_form(); ?>
This is my searchform.php
<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label for="s" class="assistive-text"><?php _e( 'Search' ); ?></label>
<input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e( 'Search' ); ?>" />
<input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search' ); ?>" />
</form>

Wordpress Custom Search by post_type

I've tried a couple of methods but I cannot seem to filter custom post_types from my search results and was hoping someone could help.
I have installed "Job Manager" and created 4 jobs which have a custom post_type = 'jobman_job'
I tried to create a manual search form and set a hidden value of post_type = jobman_job but it still returned all posts.
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<input type="text" name="s" id="s" value=""/>
<input type="hidden" name="post_type" value="jobman_job" />
<input type="submit" id="searchsubmit" value="Search" />
</form>
I then tried creating a custom search page and redirecting the search to this page as follows (i.e added page_id hidden field):
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<input type="text" name="s" id="s" value=""/>
<input type="hidden" name="page_id" value="123" />
<input type="hidden" name="post_type" value="jobman_job" />
<input type="submit" id="searchsubmit" value="Search" />
</form>
And then in the custom search page, I added the following code (as per wordpress guide - http://codex.wordpress.org/Creating_a_Search_Page) and I added the post_type of jobman_job to the query array:
global $query_string;
$query_args = explode("&", $query_string);
$search_query = array('post_type' => 'jobman_job');
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
$search_query[$query_split[0]] = urldecode($query_split[1]);
} // foreach
$search = new WP_Query($search_query);
And it still displays all posts...
What am I doing wrong? I have checked the post_type column in the wp_posts table and I have 4 unique entries...so they are there...
Any Insight?
As codex explains, after getting new data you need to replace the loop with your new data, like in this example
<?php if ($pageposts): ?>
<?php global $post; ?>
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div>
<p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>
<?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
<?php endforeach; ?>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif; ?>
Displaying posts from custom query
I simply left the html as is:
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<input type="text" name="s" id="s" value=""/>
<input type="hidden" name="post_type" value="jobman_job" />
<input type="submit" id="searchsubmit" value="Search" />
</form>
and added the following to my functions.php
function mySearchFilter($query) {
if (isset($_GET['post_type']) && $_GET['post_type'] == 'jobman_job') {
$post_type = 'jobman_job';
} else {
$post_type = 'any';
}
if ($query->is_search) {
$query->set('post_type', $post_type);
};
return $query;
};
add_filter('pre_get_posts','mySearchFilter');

Resources