Skip Navigation

[Resolved] Taxonomy as URL parameter in Button block “Link” field

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to use a Toolset Button Block to function as a link to a custom Page containing a Form. Several Form fields are set up to accept values from URL parameters, so I need to add those URL parameters to the Button block's "Link", or destination URL, field. I have been able to use Types field shortcodes successfully as URL parameter values here, but a Views taxonomy shortcode does not seem to work. The same shortcode placed outside the Button block works as expected and displays the relevant term name.

Solution: Normally I would not expect shortcodes to work in the Button block's "Link", or destination URL, field. Instead I usually recommend a custom HTML block instead, using a combination of HTML, CSS, and Toolset shortcodes as seen in the following examples:

<div class="tb-button">
    <a href="https://yourseite.de/bewerbungsformular?rmail=[types field='e-mail-adresse' output='raw' item='@ansprechpartner-stelle.parent' ][/types]&rtitle=[wpv-post-title output='sanitize']&rklinik=[wpv-post-taxonomy type='standort' format='name']&rstelle=[types field='vertragsart' output='raw'][/types]" class="tb-button__link">
        <span class="tb-button__content">Bewerben</span>
    </a>
</div>

Then add CSS in the template to apply the desired background and text color to the button, like this:

.tb-button .tb-button__link {
    background-color: rgba( 6, 147, 227, 1 );
    color: rgba( 255, 255, 255, 1 );
}
This support ticket is created 3 years, 12 months ago. 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by Christian Cox 3 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#2095539

I created a job portal. On th apply button I created a dynamic link to send parameters to the form:

hidden link field='e-mail-adresse' output='raw' item='@ansprechpartner-stelle.parent' ][/types]&rtitle=[wpv-post-title output=" sanitize"]&rklinik=[wpv-post-taxonomy type="standort" format="name"]&rstelle=[types field='vertragsart'][/types]

All of the parameters work except the wpv-post-taxonomy type="standort" format="name"
It is empty. When entering this shortcode in the form it shows the correct information, only in the link its empty. I tried dozens of variations without sucess.
Do I make a syntax mistake?

The site where you can find the link is hidden link

#2096135

Do I make a syntax mistake?
Hello, I do not see anything obviously wrong in the wpv-post-taxonomy shortcode. Can you show me how you are adding this link in the template? Is the code added to the URL field of a Button block, or have you created a custom link tag using HTML somehow? A screenshot of the template editor would be helpful for me.

Next, try inserting the following code in a custom HTML block in your template to troubleshoot the taxonomy shortcode issue a bit more:

Name format:<br />
[wpv-post-taxonomy type="standort" format="name"]<br />
Name format with separator:<br />
[wpv-post-taxonomy type="standort" format="name" separator=", "]<br />
Slug format:<br />
[wpv-post-taxonomy type="standort" format="slug"]<br />

Please take a screenshot of the results and include that in your next reply.

#2096377
Debug.jpg
Screenshot.jpg

Yes, I added the code to the URL field of the Button block - see Screenshot
I also added the results of the HTML code.

#2096979

Okay thanks for the test code. It seems that the wpv-post-taxonomy shortcode is working as expected in the test based on the screenshot you shared. As far as I know, the "link" field in the Toolset Button block is not intended to support shortcodes. However, in my local tests, I was able to get them to work...unexpectedly. The format in my local test is a bit different from yours. My format includes only single quotation marks, no double quotation marks. I also removed the space in the 'sanitize' output attribute, and added output='raw' in all Types field shortcodes. Here is the updated format:

https://yourseite.de/bewerbungsformular?rmail=[types field='e-mail-adresse' output='raw' item='@ansprechpartner-stelle.parent' ][/types]&rtitle=[wpv-post-title output='sanitize']&rklinik=[wpv-post-taxonomy type='standort' format='name']&rstelle=[types field='vertragsart' output='raw'][/types]

If I paste similar code into a Button block's "link" fields, this syntax seems to work in my local test site...even though I would not expect it to work. My example uses different custom field slugs and a differerent taxonomy slug, but the general idea is the same.

I usually recommend creating a custom link instead, to prevent problems with shortcode interpretation in the block editor. So if the Button block is not working as expected in your site after placing the code above in the Button block's "link" field, I suggest you create a custom link instead using a combination of HTML and shortcodes in a custom HTML block, something like this:

<div class="tb-button">
    <a href="https://yourseite.de/bewerbungsformular?rmail=[types field='e-mail-adresse' output='raw' item='@ansprechpartner-stelle.parent' ][/types]&rtitle=[wpv-post-title output='sanitize']&rklinik=[wpv-post-taxonomy type='standort' format='name']&rstelle=[types field='vertragsart' output='raw'][/types]" class="tb-button__link">
        <span class="tb-button__content">Bewerben</span>
    </a>
</div>

Then add CSS in the template to apply the desired background and text color to the button, like this:

.tb-button .tb-button__link {
    background-color: rgba( 6, 147, 227, 1 );
    color: rgba( 255, 255, 255, 1 );
}
#2097855

Thanks Christian, as everytime, your help was perfect and solved my issue.
My issue is resolved now. Thank you!

#2103575

Sorry Christian,
but there is still a issue. In my tests all is working well. But when visitors use the link in most times all the parameters are empty. I'm not sure why. Could it be, if a visitor is pressing the button fast, that Toolset is not ready getting the data?
I already deactivated the site where the button is in WPRocket to be sure not to have a cache issue.

Thanks
Alex

#2103911

Could it be, if a visitor is pressing the button fast, that Toolset is not ready getting the data?
No, that is a reasonable guess, but it is actually not possible here because the link HTML is constructed on the server-side before the View results are sent to the browser. The only way what you described would be possible is if the button's HTML and the Types field shortcode values were sent as different pieces of data, and combined somehow later with JavaScript. That is not the case here, the link markup is already complete when it is sent from the server. Even if a View's results are fetched with AJAX, the results for a single "page" of the View are fetched as a single data set, fully rendered in HTML by the server.

Something else is going on. Perhaps Visitors have access to another link somewhere, and that link includes no URL params. Or they could be visiting the page by typing the URL directly in the browser with no URL params.

I cannot reopen this ticket now, but I see you have another ticket created:
https://toolset.com/forums/topic/regarding-my-last-ticket-i-have-an-additional-issue-taxonomy-as-url-parameter/
I will be unavailable for the next 10 days so I will not be able to follow up here in a reasonable amount of time. I suggest you continue in the new ticket with Luo.