116 pointsSerious WPMU DEV-sterI'm new here
btray77
Member
—
20th October 2009
How would you go about creating your own search for WordPress or replacing the built in search for WordPress? I want to list items from a separate table.
So far I'm able to get the list of items, BUT it wants the url to be a post.
What I have so far:
add_action( 'wp', customsearch' );
function customsearch( $pag )
{
return;
global $wp_query, $wpdb;
if ( $wp_query->is_search )
{
$key = $wp_query->query_vars['s'];
$wpdb->query( 'SELECT id,name FROM ' .PRODUCT_LIST . ' WHERE name LIKE "%' . $wpdb->escape($key) .
'%"' );
$list = $wpdb->last_result;
$ids = array();
$names = array();
This code returns a list of items, but I have no way of specifying the URL, or anything. I had thought about trying to intercept the search page content using the_content filter, but this does not seem to work, or atleast how I tried to do it.
How would you go about creating your own search for WordPress or replacing the built in search for WordPress? I want to list items from a separate table.
So far I'm able to get the list of items, BUT it wants the url to be a post.
What I have so far:
add_action( 'wp', customsearch' );
function customsearch( $pag )
{
return;
global $wp_query, $wpdb;
if ( $wp_query->is_search )
{
$key = $wp_query->query_vars['s'];
$wpdb->query( 'SELECT id,name FROM ' .PRODUCT_LIST . ' WHERE name LIKE "%' . $wpdb->escape($key) .
'%"' );
$list = $wpdb->last_result;
$ids = array();
$names = array();
This code returns a list of items, but I have no way of specifying the URL, or anything. I had thought about trying to intercept the search page content using the_content filter, but this does not seem to work, or atleast how I tried to do it.
I really don't have a clue how to replace the built in search feature. However, you could probably modify our sitewide search plugin to meet your needs. 90% of the code you would need is in there at least.
Responses (3)
Erstwhile founder — 20th October 2009 #
Hiya,
I really don't have a clue how to replace the built in search feature. However, you could probably modify our sitewide search plugin to meet your needs. 90% of the code you would need is in there at least.
Thanks,
Andrew
Member — 20th October 2009 #
I had been looking at it, but have been unable to use it so far...
Thanks for the information
-Brad
Erstwhile founder — 20th October 2009 #
Happy to provide exampes if you're stuck on a particular bit.
Thanks,
Andrew
Become a member