Hide Views

By: Peter S | Asked: 02/12/2023
Peter S asked 1 year ago


i have a page with the search at the top and the view below it. When you search it filters the results. 

What I want to do is have the search at the top and the view hidden and for only the filtered results to appear. 

Is this possible? 


Chris Titus replied 1 year ago

I just had this issue.

I placed the search form on page A.

When someone searches, it redirects to page B/?parameter.

Page B has the search form and the view.

Rob LeVineRob LeVine replied 1 year ago

If Chris' issue is the one you're having as well, you could also do this on a single page with a little bit of jQuery to hide the view until there are any parameters in the URL related to the search. i.e., "if search parameters, show view, otherwise hide it"

Chris Titus replied 1 year ago

Thank you for pointing us in the right direction Rob. I was able to solve this with the following code:

$( document ).ready(function() {
var currentURL = window.location.href; //grab the current window location

var targetDiv = $("#add_id_here"); //change this as per your code

targetDiv.hide(); //hide the div by defualt

if (window.location.href.indexOf('?parameter') != -1) { //add the parameter string
targetDiv.show(); //show the div if matched the current location

Peter S replied 1 year ago

Hey Chris,
Thanks for sharing. I've no experience with jQuery.
Can you show me an example of the code with all the parameters filled out?

Chris Titus replied 1 year ago

Hi Peter - what is the URL that your search form points to?

1 Answers
Peter S answered 1 year ago

Solved the problem using this code:

function show_hide_div() {
if (isset($_GET['lname'])) {
echo "jQuery('.with_frm_style.frm-responsive-table.Newtownbreda_View').show();";
} else {
echo "jQuery('.with_frm_style.frm-responsive-table.Newtownbreda_View').hide();";
add_action( 'wp_footer', 'show_hide_div' );

You put it in your funtions.php folder.

if (isset($_GET['lname'])) - You must replace "lname" with the paramenter that triggers the search

"jQuery('.view').show();"; - You must replace "view" with the class ID of your view.

Victor Font replied 1 year ago

That’s a nice alternative than doing it just in jQuery. Good job!

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community