Skip Navigation

[Gelöst] How to check the URL param value conditionally using Toolset

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
How to check the URL param value conditionally using Toolset

Solution:
You can use the shortcode [wpv-search-term] to check the URL param value conditionally.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/wpv-conditional-if-check-if-selected-value-not-specified/page/2/#post-2095557

Relevant Documentation:
=> https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/
=> https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-search-term

This support ticket is created vor 2 Jahre, 9 Monate. There's a good chance that you are reading advice that it now obsolete.

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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 20 Antworten, has 2 Stimmen.

Last updated by davidm-13 vor 2 Jahre, 9 Monate.

Assisted by: Minesh.

Author
Artikel
#2094325

I have the following code

  <u>Medicinal Complaint / Use</u>: <b>[get_term_data_custom parameter="wpv-complaint-search-key" taxonomy="complaint-search-key"]</b> <br>

Which displays the term selected from a taxonomy list (complaint-search-key)
If nothing is selected then it returns:

Medicinal Complaint / Use: not specified

I want to use a wpv-conditional so that the above line is not displayed. ie the line is only displayed if a term is selected.

What would be the format of this wpv-conditional?

Thanks for your help

#2094337

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Here is the doc with the example [wpv-conditional] shrotcode to check at least one term assigned to post:
=> https://toolset.com/documentation/legacy-features/views-plugin/displaying-taxonomies-conditionally/#one

#2094445

Hi Minesh, Thanks for this.
I tried this code - from the link you sent me:

[wpv-conditional if="('[wpv-post-taxonomy type='complaint-search-key' format='slug' ]' ne '' )"]
  <u>Medicinal Complaint / Use</u>: <b>[get_term_data_custom parameter="wpv-complaint-search-key" taxonomy="complaint-search-key"]</b> <br>
[/wpv-conditional]

Now whether I select an item from the taxonomy or not the text "Medicinal Complaint / Use : taxonomy="complaint-search-key" / not Specified " never appears.

#2094449

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

That is strange. Can you please share problem URL where you added the conditional statement as well as admin access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2094649

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please tell me where you added the shortcode "get_term_data_custom"?

Also - do you mean that when the shortcode "get_term_data_custom" does not return any value - you do not want to display the label "Medicinal Complaint / Use" - right?

#2094779

in functions.php

add_shortcode( 'get_term_data_custom', 'get_term_data_custom_func');
function get_term_data_custom_func($atts){
    $parameter = $atts['parameter'];
    $taxonomy = $atts['taxonomy'];
      
    if ( (!empty($parameter)) && (!empty($taxonomy)) && (!empty($_GET[$parameter])) ) {
        $category = get_term_by('slug', $_GET[$parameter], $taxonomy, 'ARRAY_A');
        if($category) {
            return $category['name'];
        }
    }
	    else
    {
        return 'not specified';
    }
}
#2094847

When get_term_data_custom returns 'not specified' I don't want to display the label "Medicinal Complaint / Use" or 'not specified'

Thanks

#2095337

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Just to ensure that you have added the conditional shortcode within the view's loop so the code will run with every loop iteration.

Do you want that when the whole view's loop finishes and it returns the "not specified" for every loop iteration then you do not want to display the label "Medicinal Complaint / Use" - right?

#2095379
notspecified1.JPG
notspecified.JPG

Hi Minesh,
Here's a couple of screenshots of the results page.
What I need is notspecified1.jpg - with no "Medicinal Complaint / Use: not specified" line

Thanks

#2095411

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

On this page: hidden link

I can see its displayed as:

Medicinal Complaint / Use: not specified

As it's displaying "not specified" - you want to completely hide the above line on the page - right?

#2095419

Correct

Thanks

#2095423

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've adjusted the code as given under:

[wpv-conditional if="('[get_term_data_custom parameter='wpv-complaint-search-key' taxonomy='complaint-search-key"]' ne 'not specified' )" ]
  <u>Medicinal Complaint / Use</u>: <b>[get_term_data_custom parameter="wpv-complaint-search-key" taxonomy="complaint-search-key"]</b> <br>
[/wpv-conditional]  

Also, I've registered the custom shortcode at:
- Toolset -> Settings -> Front-end Content tab -> Functions inside conditional evaluations
=> hidden link

Can you please confirm it works as expected.

#2095461

Hi Minesh,

Not working.

Medicinal Complaint / Use: line doesn't appear at all whether specified or not specifed

#2095469

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please specify and tell me where exactly you are setting up the "Functions inside conditional evaluations" in admin?

Can you please share one test post where you setup the "Functions inside conditional evaluations"?

It seems to me first I will require to understand your workflow, as you added the conditional statement out side the view's loop that is why we do not know what content you setup for what post as we added the condition outside the view's loop.

#2095497
Home-med-complaint-search.JPG
results-med-complaint-search.JPG

Hi Minesh,
Jamal helped me set this up (so not to clear on details) - to search taxonomies in child posts and display unique parent post titles.
The search is initiated on the home page - screenshot Home-med-complaint-search.jpg, after clicking search button receive the results - results-med-complaint-search.jpg

Thanks

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.