I'm working on a WordPress site for a client, and I need a custom search box in the header. The site is using their external e-commerce tool from CNET. So the e-commerce pages in their WordPress site consist of an iframe displaying a URL to their CNET store.
So on the store search page, the iFrame URL looks like:
https://store.com/ourstore/Search/Category/?search_string=
Obviously, here you can pass in your search term into the URL string. So if I wanted to search for Dell Laptops, the URL to use in the iFrame would be:
https://store.com/ourstore/Search/Category/?search_string=dell%20laptop
What I need to do is put a search box in the header, and pass along the search term entered into the search box to the advanded search page, and put the search term into the iFrame's URL.
Is there a way to do this? I'm pretty new to WordPress, but I've been writing PHP code forever. I'm just not sure where to look in WordPress.
If I understand your question, you should be able to use the_search_query();
https://codex.wordpress.org/Function_Reference/the_search_query
This function just outputs whatever the current WordPress search query is. So in your code to call your iFrame, you could do something like this:
<iframe src="https://store.com/ourstore/Search/Category/?search_string=<?php echo get_search_query(); ?>">
Now, since the search term is going to need to be encoded for use in a URL, you can use the PHP function urlencode();
<iframe src="https://store.com/ourstore/Search/Category/?search_string=<?php urlencode(get_search_query()); ?>">
Related
I am working on a search box. So far, I am able to search and redirect to Google with the correct XML output. However, I don't want to redirect the URL, but show the produced XML where my search box is placed.
Currently, My search box is located on search.php and after clicking search it redirects me to google with XML output. I want to stay on search.php with produced XML.
I researched that Iframe could be useful, but I just want to know the best way to achieve the solution in context of PHP.
I hope someone can help me with this.
Currently when someone does a search on my website, the page that is returned has the URL:
http://www.dublinjobs.ie/main/index.
(Let's call this "the search results URL").
If you scroll to the bottom of the page you will see the pagination URLs use the form
http://www.dublinjobs.ie/main/index/2/basic/php/0/relevance/all/0/0/20/0/0/0/0/0/0/0.
(Let's call this "the pagination URL").
Is there some way I can change my website so the search results URL has a similar format to the pagination URL?
I need to to fix this because currently the search results URL cannot be bookmarked or emailed to someone as it is unspecific.
I'm guessing the solution is some sort of internal URL rewrite but I am not sure how to do this.
Thank you for your assistance.
EDIT: I don't want to just use a GET instead of a POST as I want to be able to control the URL layout.
Even your pagination URL doesn't include search term. What you need is to include search keywords in the URL itself to make it unique which can be bookmarked or shared.
Most likely you're using method="POST" in your search form which needs to change to: method="GET".
Note that it will make your URL like:
http://www.dublinjobs.ie/main/index?search=keyword
OK. I have a dirty hack fix.
I am using a header redirect in my PHP code to send them to the URL I want after doing my processing.
I am working on a wordpress website where i want to redirect my search from my wordpress site to another website and display the results of that search on that website , with the contents of that website
Assuming you're using the standard WordPress search form, you could hook into the get_search_form filter, and change the action attribute for the form. So something like:
add_filter('get_search_form', 'so_change_search_form_action', 10, 1);
function so_change_search_form_action($form) {
return preg_replace('#action="[^"]*"#','action="http://www.example.com/search"',$form);
}
That's completely untested code, but hopefully it'll get you started (I assume you have code on the destination server to handle the request).
I have a Textbox in a php page. If i enter a value in it, have to redirect to another website and search for the keyword i have entered in it. how to do this in php?
If the site you want to search is something like google you can use their API so with just a few changes in your html code, your form will search the web for the text entered. See this for example.
In the case the site you want to search has no built in tool or such functionality, you are basically hoping that the site is using the get method for searching, so you can build php location headers, after you process the entered information.
So if someone enters the term "find this" in your search box, you will have to do something like
header("Location: site_im_searching_in/blablabla?search=find+this")
Though the second method is anything but recomended because any time the site changes the way they process URL's or the syntax they use, you will be left with a broken box.
I'm trying to enter a list of items into Google Base via an XML feed so that, when a user searches for one of these items and then clicks the search result link in Google Base (or plain Google), the user is directed to a dynamic Web page on my Web site. I'm assuming that the only way to specify a specific link (either static or dynamic) is through the attribute in the XML feed. Is that correct? So, for example, if my attribute is:
http://www.example.com/product1-info.html
the user will be directed to the product1-info.html page.
But if, instead of a static product page, I want to have the user redirected to a dynamic page that generates search results from my local database (on my Web site) for all products containing the keyword "product1", would I be able to do something like this?:
http://www.example.com/products.php?productID=product1
Finally, and most importantly, is there any way to specify this landing page (or any specific landing page) from a "regular" Google search? Or is it only possible via Google Base and the attribute? In other words, if I put a bunch of stuff into Google Base, if any of it shows up in a regular Google search, is there a way for me to control what parameters get passed to the landing page (and thus, what search is performed on the landing page), or is that out of my control? I hope I explained this correctly. Thanks in advance for any help.
first question: Yes, urls containing a query_string part are allowed.
http://base.google.com/support/bin/answer.py?hl=en&answer=78170 says:XML example:
<link>http://www.example.com/asp/sp.asp?cat=12&id=1030</link>
--
Let me rephrase the second question to see if I understand it correctly (might be completely on the wrong track): E.g. products.php?productID=product1 performs a db-search for the product "FooEx" and products.php?productID=product2 for "BarPlus". Now you want google to show the link .../products.php?productID=product1 but not ....?productId=product2 if someone searched for "FooEx" and google decided that your site is relevant? Then it's the same "problem" we all face with search engines: communicate what each url is relevant for. I.e. e.g. have the appropriate (and only the appropriate) keywords appear in the title/h1 element of the page, avoid linking to the same contents with different urls (e.g. product.php?x=1&productId=1 <-> product.php?productId=1&x1, different urls requesting most probably the exact same contents), submit a sitemap, and so on and on....
edit:
and you can avoid the query-string part all together by using something like mod_rewrite (e.g. the front controller for the zend framework makes use of it) or by parsing the contents of $_SERVER["PATH_INFO"] (this requires the webserver to provide that information), e.g. http://localhoast/test.php/foo/bar -> $_SERVER['PATH_INFO']=='/foo/bar'
Also take a look at the link to this thread: How to redirect a Google search result to a dynamic Web page?, it contains the title of the thread, but SO is perfectly happy with How to redirect a Google search result to a dynamic Web page?, too. The title is "only" additional data for search engines and (even more) the user.
You can do the same:
http://www.example.com/products.php/product1/FooEx <-> http://www.example.com/products.php/product2/BarPlus