| | #1 |
| Professional Copywriter War Room Member Join Date: 2006 Location: In the trenches...
Posts: 1,803
Thanks: 685
Thanked 643 Times in 261 Posts
|
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! |
| |
| | #2 |
| HyperActive Warrior War Room Member Join Date: 2014 Location: New Zealand
Posts: 210
Thanks: 25
Thanked 81 Times in 71 Posts
|
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 |
| | |
| |
| The Following 2 Users Say Thank You to emptee For This Useful Post: |
| | #3 |
| Active Warrior Join Date: 2014 Location: Oregon, USA
Posts: 56
Thanks: 17
Thanked 9 Times in 9 Posts
|
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 |
| |
|
| Bookmarks |
| Tags |
| wordpress |
| |