Magento search box on Wordpress site - php

I have a WP site on http://subdomain.example.com and a Magento site at http://example.com.
I was wondering what is the easiest way to add a Magento search box on the WP installation?
This is the WP search box code, but i dont know what parameter to modify since i have no idea how Magento works :(
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div>
<label class="screen-reader-text" for="s"><?php _x( 'Search for:', 'label' ); ?></label>
<input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="<?php echo esc_attr_x( 'Search', 'submit button' ); ?>" />
</div>
</form>
Any help would be greatly appreciated!

You can make a php script that gets the data from the magento site every time someone searchs . that would probably be the simplest way.

Put the Magento catalogsearch url in the form action, and an input field with name attribute value "q" such as:
<form method="get" action="http://example.com/catalogsearch/result/">
<input type="text" value="" name="q" />

Related

Control Search Parameters in PHP Wordpress

Search parameters are null in PHP Wordpress
When user press search button, it make query string parameters even if search fields are empty
www.example.com/?ssc=&sst=&s=
How i can check it and remove (Don't Allow) null parameters from url
If you know where your form is situated, add required to input text
<input type="text" name="s" id="search" value="<?php the_search_query(); ?>" required />
or else create searchform.php in your theme directory and add following code
<form action="/" method="get">
<label for="search">Search in <?php echo home_url( '/' ); ?></label>
<input type="text" name="s" id="search" value="<?php the_search_query(); ?>" required />
<input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" />
</form>

Wordpress search function not working

I am fleshing out my first custom Wordpress theme and trying to hook up the search. Now I am following the codex but does not appear to be working correctly. Perhaps I am doing something wrong?
I have added the theme support as this is using the HTML field method.
so here is my search field:
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
<label>
<input type="search" class="search-field" placeholder="What are you looking for?" value="<?php echo get_search_query() ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
</label>
<br />
<button class="button-search">Find items</button>
</form>
And I have created a search.php with the usual template page bits along the top, created the search page as a page in wordpress, yet when I search I can see the post request in the URL but the page is blank. I am cleary doing something wrong here?
This should work for you
<form role="search" method="get" class="search-form" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label>
<input type="text" class="search-field" placeholder="What are you looking for?" value="<?php echo get_search_query() ?>" name="s" id="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ) ?>" />
</label>
<br />
<input type="submit" class="button-search" id="searchsubmit" value="Find items" />
</form>

Wordpress not filtering posts

I'm making a Wordpress template on my own. On the top of the header, there is a fixed search input, so the user can search for any posts with a determinate tag whenever he wants to.
The problem is that when I type a tag keyword on the input, it always shows all the posts, not filtering any of it at all.
But when I search for a keyword that has no tag registered, it returns a 404.php error page.
One curious thing is that when there is a tag keyword, the link appears like this:
/wordpress/tag/name-of-the-tag/
And when there is no tag with that keyword, it appears as:
/wordpress/?tag=name-of-the-tag/
My form code is right below:
<form method="get" action="<?php echo esc_url( home_url( '/' ) );?>">
<input id="s" type="text" name="tag" onfocus="if (this.value=='Buscar...') this.value = '';" onblur="if (this.value=='') this.value = 'Buscar...'" name="search" class="form-search" value="Buscar..."/>
</form>
You've add the name attribute twice. With a value tag and search. Remove all of them and add a name="s"
This is from CODEX
<form role="search" method="get" id="searchform" class="searchform" action="<?php echo esc_url(home_url('/')); ?>">
<div>
<label class="screen-reader-text" for="s"><?php _x('Search for:', 'label'); ?></label>
<input type="text" value="<?php echo get_search_query(); ?>" name="s" id="s" />
<input type="submit" id="searchsubmit" value="<?php echo esc_attr_x('Search', 'submit button'); ?>" />
</div>
</form>

In a Wordpress theme (using get_search_form()), how can I add placeholder text to the search box?

I am trying to create a theme and I am displaying a search box in the header using:
<?php get_search_form(); ?>
Is there a way that I can get placeholder text to show in that box?
I ended up figuring out that if I don't have a file called "searchform.php" in my theme folder, Wordpress displays is default form that doesn't include any placeholder text:
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<div><label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
I created a new file called "searchform.php" in my theme folder and modified the default form to include the placeholder text:
<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
<div>
<input type="text" value="" name="s" id="s" placeholder="Search gear, clothing, & more.." />
<input type="submit" id="searchsubmit" value="Search" />
</div>
</form>
make searchform.php in theme folder and place that code in it
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
<div>
<input class="text" type="text" value=" " name="s" id="s" />
<input type="submit" class="submit button" name="submit" value="<?php _e('Search');?>" />
</div>
</form>
Change whatever you want ! like class,placeholder,text any thing you want but not change like name, id and form attribute
Thanks
The WP codex has an example with a placeholder:
If your theme supports HTML5, which happens if it uses
add_theme_support('html5', array('search-form')), it will output the
following HTML form. This is the case since WordPress 3.6.
<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>
If you don't want to use HTML5 tags and attributes, you can create placeholders with JavaScript.
The official get_search_form explained the more flexible modified that could add in your funtions.php.
check out here with CodeX commit.
TL;DR
Checkout the code below.
function wpdocs_my_search_form( $form ) {
// replace the new form on your own.
$form = '<form role="search" method="get" id="searchform" class="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;
}
add_filter( 'get_search_form', 'wpdocs_my_search_form' );

How can I replace a character in a wordpress search query?

For example, how would I go about replacing www.example.com/search/mark+twain with www.example.com/search/mark_twain ?
The form to search looks like this:
<form role="search" method="get" id="searchform" action="<?php echo home_url('/'); ?>">
<label class="visuallyhidden" for="s"><?php _e('Search for:', 'roots'); ?></label>
<input type="text" value="" name="s" id="s" placeholder="<?php _e('Search Courses/Material'); ?> ">
<input type="submit" id="searchsubmit" value="<?php echo attribute_escape(__('Search')); ?>" class="button">
</form>
I'm not quite sure how you're using this or where exactly you're using that query, but you could always use string replace:
str_replace('+','_',$query)
That's the best answer I can give with this vague a question.
PHP Manual
For jquery (which wordpress makes use of) you could do something like:
$('#sear form').submit(function(){
$(this).val($(this).val().replace(' ','_'));
});
I think that's correct. I'm not where I can try it, but it should work.

Categories