Skip Navigation

[Resolved] Possible to display or hide conditional block based on GET/url parameter?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 voice and has 0 replies.

>
Author
Posts
#2701962

Tell us what you are trying to do?
I'd like to use a conditional block to display or hide content based on the presence of a GET/url parameter; i.e. "step=1" or "start=true", etc.

Is there any documentation that you are following?
Dated forum post at https://toolset.com/forums/topic/conditional-display-based-on-url-parameter/ can this apply or be done for a conditional guttenburg block?

Is there a similar example that we can see?
Similar sentiments at https://toolset.com/forums/topic/conditional-display-based-on-url-parameter/

What is the link to your site?
Site under development.

#2702093

Found a resolution:
1) Create a custom function i.e. place the following in the theme's function.php file:
```
function has_param1() {
if ( isset( $_GET['param1] ) ) {
return 1;
}else{
return 0;
}
}
```

Note that I had to return integers, returning booleans or strings did NOT work. Further, one has to use the conditional block with the following rules:

Custom Function
has_param1

Note: you will need to register the function via Toolset -> Settings -> Front End Content -> Functions inside conditional evaluations; and add the authored function in question.

The rule set is '=' to 'Static Value' 1.

Note: Setting a static value to 'true' (as a boolean) or an arbitrary string, or using the ruleset of 'Empty', did NOT work in any combination.

This is rather cumbersome and convoluted to just detect the presence of a GET parameter in the URL, much less check its actual value.

Perhaps there is an easier way or room for improvement here.