WordPress Search Problems - wordpress

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>

Related

Submitting comments navigate to blank page in WordPress

On my single.php, I have cuustom code for comments, when I submit a comment, it goes to a blank page with url "https://mosquitojoefranchise.com/wp-comments-post.php". However if I use <?php comments_template(); ?>, then it's working fine. My code is as follows:
<div id="comments">
<ol>
<?php
$pId = $post->ID;
$args = array(
'number' => '5',
'post_id' => $pId, // use post_id, not post_ID
);
$comments = get_comments($args);
foreach($comments as $comment) :
?>
<li>
<div class="avatar"><?php echo get_avatar( $comment, 68 ); ?></div>
<div class="comment_right">
<div class="comment_info">
<?php echo($comment->comment_author);?> <span> </span><?php comment_date('F-j-Y'); ?>
</div>
<?php echo ($comment->comment_content);?><br>
<ul class="comment-links">
<li style="list-style:none !important;"><a aria-label="Reply to Mr WordPress" onclick="return addComment.moveForm( "div-comment-1", "1", "respond", "1" )" href="<?php echo esc_url( get_permalink() ); ?>?replytocom=<?php echo ($comment->comment_ID); ?>#respond" class="comment-reply-link">Reply</a></li>
</ul></div>
<div class="clear"></div>
</li>
<?php
endforeach;
?>
</ol>
</div>
<?php
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) {
//comments_template();
//$file='/short-comments.php';
//comments_template($file);
if ('open' == $post->comment_status) : ?>
<div id="respond">
<h3><?php comment_form_title( 'Post Comments', 'Post Comments to %s' ); ?>.</h3>
<div class="cancel-comment-reply">
<small><?php cancel_comment_reply_link(); ?></small>
</div>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
<p>You must be logged in to post a comment.</p>
<?php else : ?>
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform" class="commentform">
<?php if ( $user_ID ) : ?>
<p>Logged in as <?php echo $user_identity; ?>. Log out »</p>
<?php else : ?>
<input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" placeholder="First Name" aria-label="First Name" />
<input type="text" name="last_name" id="last_name" size="22" tabindex="2" placeholder="Last Name" aria-label="Last Name" />
<input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" placeholder="Email" aria-label="Email" />
<input type="text" name="phone" id="phone" size="22" tabindex="4" placeholder="Phone" aria-label="Phone" />
<?php endif; ?>
<textarea onBlur="if (this.value == '') this.value = 'Your Comment';" onFocus="if (this.value == 'Your Comment') this.value = '';" name="comment" id="comment" cols="100" rows="10" tabindex="4" aria-label="Your Comment">Your Comment</textarea> <br>
<fieldset id="submit">
<legend style="display: none;">Comment Submit</legend>
<input name="submit" type="submit" tabindex="5" value="Submit" class="btn btn-blue mahi" />
</fieldset>
<input type="reset" value="Clear" class="btn">
<?php comment_id_fields(); ?>
<?php do_action('comment_form', $post->ID); ?>
</form>
<?php endif; // If registration required and not logged in ?>
</div>
<?php endif; // if you delete this the sky will fall on your head
}
endwhile;
?>
</div>
I do not understand why it is going to blank page, I have given correct form action, still it's not working. Please have a look on the custom code and help me in this case.

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>

Search Form not working on 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.

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');

Can we display Joomla Login Module in WordPress?

Hi I am using Joomla and WordPress both and I use a single sign-on plugin which is Joomla based. Now the issue is that it is kind of one-way login management.
What I mean is When a user logs into Joomla he automatically gets logged into WordPress and similarly when a user registers into Joomla his details are automatically replicated into WordPress. This activity does not happen when a user logs into or registers from WordPress.
So I wanted to know Is there a way to display the Joomla Login module in the WordPress pages so that when a user logs in from a WordPress page he gets his credentials checked from the Joomla database and the rest is handled by my Joomla Single-signon plugin.
Or is there a better way around?
Kindly suggest.
The code for my Joomla Login Module is somewhat like this:
<?php
defined('_JEXEC') or die('Restricted access'); ?>
<?php if($type == 'logout') : ?>
<form action="index.php" method="post" name="login" id="form-login">
<?php if ($params->get('greeting')) : ?>
<div class="user-greeting">
<?php if ($params->get('name')) : {
echo JText::sprintf( 'HINAME', $user->get('name') );
} else : {
echo JText::sprintf( 'HINAME', $user->get('username') );
} endif; ?>
</div>
<?php endif; ?>
<div class="readon"><input type="submit" name="Submit" class="button" value="<?php echo JText::_( 'BUTTON_LOGOUT'); ?>" /></div>
<input type="hidden" name="option" value="com_user" />
<input type="hidden" name="task" value="logout" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
</form>
<?php else : ?>
<?php if(JPluginHelper::isEnabled('authentication', 'openid')) :
$lang->load( 'plg_authentication_openid', JPATH_ADMINISTRATOR );
$langScript = 'var JLanguage = {};'.
' JLanguage.WHAT_IS_OPENID = \''.JText::_( 'WHAT_IS_OPENID' ).'\';'.
' JLanguage.LOGIN_WITH_OPENID = \''.JText::_( 'LOGIN_WITH_OPENID' ).'\';'.
' JLanguage.NORMAL_LOGIN = \''.JText::_( 'NORMAL_LOGIN' ).'\';'.
' var modlogin = 1;';
$document = &JFactory::getDocument();
$document->addScriptDeclaration( $langScript );
JHTML::_('script', 'openid.js');
endif; ?>
<form action="<?php echo JRoute::_( 'index.php', true, $params->get('usesecure')); ?>" method="post" name="login" id="form-login" >
<?php echo $params->get('pretext'); ?>
<fieldset class="input">
<p id="form-login-username">
<label for="modlgn_username"><?php echo JText::_('Username') ?></label><br />
<input id="modlgn_username" type="text" name="username" class="inputbox" alt="username" size="18" />
</p>
<p id="form-login-password">
<label for="modlgn_passwd"><?php echo JText::_('Password') ?></label><br />
<input id="modlgn_passwd" type="password" name="passwd" class="inputbox" size="18" alt="password" />
</p>
<?php if(JPluginHelper::isEnabled('system', 'remember')) : ?>
<p id="form-login-remember">
<input type="checkbox" name="remember" class="checkbox" value="yes" alt="<?php echo JText::_('Remember me'); ?>" />
<label class="remember">
<?php echo JText::_('Remember me'); ?>
</label>
</p>
<?php endif; ?>
<div class="readon"><input type="submit" name="Submit" class="button" value="<?php echo JText::_('LOGIN') ?>" /></div>
</fieldset>
<ul>
<li>
<a href="<?php echo JRoute::_( 'index.php?option=com_user&view=reset' ); ?>">
<?php echo JText::_('FORGOT_YOUR_PASSWORD'); ?></a>
</li>
<li>
<a href="<?php echo JRoute::_( 'index.php?option=com_user&view=remind' ); ?>">
<?php echo JText::_('FORGOT_YOUR_USERNAME'); ?></a>
</li>
<?php
$usersConfig = &JComponentHelper::getParams( 'com_users' );
if ($usersConfig->get('allowUserRegistration')) : ?>
<li>
<a href="<?php echo JRoute::_( 'index.php?option=com_user&view=register' ); ?>">
<?php echo JText::_('REGISTER'); ?></a>
</li>
<?php endif; ?>
</ul>
<?php echo $params->get('posttext'); ?>
<input type="hidden" name="option" value="com_user" />
<input type="hidden" name="task" value="login" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>
<?php endif; ?>
Take a look at JFusion. It was written specifically to handle single sign on/login/registration for Joomla and many other popular projects. Here is the WP specific info -
http://www.jfusion.org/docs/doku.php?id=start#wordpress_3

Resources