Skip Navigation

[Resolved] Conditional calls seem to be slowing site down

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

Problem:
Client has lots of wpv-conditional tests in a custom archive which he believes is slowing down generating the page.

Solution:
The custom archive was re-worked to remove the need for the wpv-conditional shortcodes, in this case by adding custom fields for terms which are uniquely available on the taxonomy archive. Read the thread to see if it is applicable in your case.

0% of people find this useful.

This support ticket is created 6 years, 6 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by chrisB-30 6 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#918267

Hello,

I am using a content template (with Beaver Builder) to render the profiles on my site - like this one:
hidden link

The profiles seem to render slower then the rest of my site - even slower than other pages that are using Toolset with multiple images.

The large profile image seems to be the culprit as it is always the last thing to render on the page. The images are optimized and should load quickly so I believe the problem may be with the conditional calls that wrap the image to create a custom affiliate link.

Here is a sample of what the conditional code looks like:

----------------

[wpv-conditional if="( has_term('amolatina', 'agency', null) eq '1' )" ]
hidden link field='id' output='raw'][/types]%26afid%3D20103%26subafid%3D{affiliate_id}%26transaction-id%3D{transaction_id}%26offer-id%3D{offer_id}" target="_blank" rel="noindex noopener">
[types field='logo' alt='%%ALT%%' title='%%TITLE%%' width='300' align='center' ][/types]<img class="aligncenter" style="margin-top:-50px" src="hidden link" />

[/wpv-conditional]

[wpv-conditional if="( has_term('anastasiadate', 'agency', null) eq '1' )" ]
hidden link field='id' output='raw'][/types]%26afid%3D20068%26subafid%3D{affiliate_id}%26transaction-id%3D{transaction_id}%26offer-id%3D{offer_id}%26RMC%3D{aff_sub}%26utm_source%3DHasOffers%26utm_medium%3DCPA%26utm_campaign%3DFirstOrder" target="_blank" rel="noindex noopener">
[types field='logo' alt='%%ALT%%' title='%%TITLE%%' width='300' align='center' ][/types]<img class="aligncenter" style="margin-top:-50px" src="hidden link" />

[/wpv-conditional]

-------------------------------------------------

There are 16 of these conditionals in total. The purpose is to query the taxonomy "Agency" - and depending on which agency the profile belongs to it will pick that agencie's conditional code - then insert information drawn from the custom field "ID".

That creates a custom affiliate link for the image.

Is it possible that 16 conditionals is too many and is slowing the page load?

Is this the most efficient way to perform this function? If not can you point me to some documentation on a more streamlined way.

Thanks!

#918301

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Chris

First observation is that I visited that page and it seemed to load pretty quickly, and using the network tab I saw Time To First Byte at 1.1s, which is essentially the time it takes the server to assemble the page HTML and begin to send it to the browser, so it's not obvious there is a problem with generating the markup (i.e. wpv-conditional has already been parsed).

In any case, you might not need all of these conditionals.

I can't quite tell what basis your generating your affiliate links on, but it looks to me like this is probably a candidate for using term meta fields.

So if you have a taxonomy for the agency, then you can create custom fields for each term.

That could be a URL field, or it could be something use (e.g. and ID) to construct an affiliate link in a standard format.

So the amolatina term would have a custom field that is or which you use to construct the affiliate link for that agency.

The thing is, the context to output such a term field would need to be a taxonomy View (which would include a Query Filter to set the term based on where the View was inserted).

If you want to go down this route, you could shift the whole part that generates the image wrapped in a link into the Loop Output section of this View.

But then the types fields that you were using originally wouldn't have the right post context anymore (because they are in a taxonomy View) so that last part of the puzzle would be to pass the post ID using wpv-post-id as a shortcode attribute where you insert the taxonony View, and then in the taxonomy View add an id attribute to your types fields where the value comes from the shortcode attribute (using wpv-attribute: https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-attribute).

See https://toolset.com/documentation/user-guides/passing-arguments-to-views/ for more details.

So, you would add a View but save up to 16 conditional shortcodes.

#918611

Thanks for the reply...

That does sound more logical.

I think I may have tried something like that to begin with. The problem is that the profile "ID" field needs to be inserted INSIDE the affiliate link like this:

hidden link more variables-here

Unfortunately, it is like that for the majority of the affiliate links.

Before I spend 12 hours trying to figure this out can you tell me if this would even be possible with your method.

Is there any way to insert a variable placeholder for the ID# inside the url agency term field - that I could then replace in the loop. (or something like that)

Thanks again....

#918706

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Well, I haven't studied how each of the affiliate links for each of the agencies is formatted, but the order of the URL parameters will not matter.

site.com/?a=alpha&b=beta&g=gamma&d=delta

is the same as

site.com/?a=alpha&g=gamma&d=delta&b=beta

So if all of your affiliate links consisted of some series of parameters that may be specific to them plus an ID parameter which all links use, then you could create two term meta fields for each agency term

base-url (e.g. site.com/?a=alpha&b=beta&g=gamma&d=delta)

and affiliate-id (e.g. 10627)

then you can output the links as

<a href="[types termmeta='base-url' output='raw'][/types]&affiliate-id=[types termmeta='affiliate-id'][/types]">Link to agency profile</a>

...which would generate the link

<a href="site.com/?a=alpha&b=beta&g=gamma&d=delta&affiliate-id=10627">Link to agency profile</a>
#918773

Got it!

Thanks again...