Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 13th May 2015, 11:08 PM   #1
Professional Copywriter
War Room Member
 
Nick Brighton's Avatar
 
Join Date: 2006
Location: In the trenches...
Posts: 1,803
Thanks: 685
Thanked 643 Times in 261 Posts
Default
How can I do this in Wordpress?
Share on: 
fb share twitter share gplus share more share

Hey folks,

I want visitors to land on my site, and have the option to check a bunch of boxes, and hit "GO" and the results they see are all posts/pages that feature the things they checked off in the boxes (or as many of them as possible.)

Basically, it's like a search tool for Wordpress that, instead of typing in a keyword on the site search box, people check off particular things they're looking for, and the site shows those posts/pages that are most relevant.

Pretty simple, but wondering...

Is there a plugin that can already do this?

How would you approach this?

Thanks!
Nick Brighton is offline  
Unread 14th May 2015, 02:28 AM   #2
HyperActive Warrior
War Room Member
 
emptee's Avatar
 
Join Date: 2014
Location: New Zealand
Posts: 210
Thanks: 25
Thanked 81 Times in 71 Posts
Default
Re: How can I do this in Wordpress?
Share on: 
fb share twitter share gplus share more share

Hey mate,

I'd be surprised if there was a plugin that already did this - but it's a relatively trivial thing to do if you know PHP at all

I'd tackle it by....

1) Creating the form as a shortcode in your functions.php, as a plugin.. whatever, something like this would work:

function do_my_cool_search_shortcode( $atts, $content = null ) {
?>
<form>
Check 1 <input type="checkbox" name="check1">
Check 2 <input type="checkbox" name="check2">
...
<input type="hidden" name="did_cool_search">
<input type="submit" value="Do the search!">
</form>
<?php
}
add_shortcode( 'my-cool-search', 'do_my_cool_search_shortcode' );

2) Hook into parse_query if the form was hit.. and throw in tags based on the checkboxes..

function do_cool_search( $query )
{
$tags = [];
if( isset($_POST['check1']) )
{
$tags[] = 'check1_tag_name';
}
if( isset($_POST['check2']) )
{
$tags[] = 'check2_tag_name';
}
$query->query_vars['tag__in'] = explode(',',$tags);
$query->query['tag__in'] = explode(',',$tags);
}

if( isset( $_POST['did_cool_search'] ) )
{
add_action('parse_query','do_cool_search');
}

That's uhh.. pretty much it in theory, all the code was untested and pretty much written on the fly, but it should do the trick unless I've missed something silly..

Cheers,
Michael

emptee is offline  
The Following 2 Users Say Thank You to emptee For This Useful Post:
Unread 26th May 2015, 08:00 PM   #3
Active Warrior
 
Join Date: 2014
Location: Oregon, USA
Posts: 56
Thanks: 17
Thanked 9 Times in 9 Posts
Default
Re: How can I do this in Wordpress?
Share on: 
fb share twitter share gplus share more share

Emptee laid it out so nicely for you to do exactly what you want based off what you tag the post with. That was a way cool example Emptee.

I didn't proof the syntax, but there is enough there that you should be able to complete as an novice/intermediate programmer.

Best,
Will
Techalo is offline  
Closed Thread


Bookmarks

Tags
wordpress


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 04:08 PM.