[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, 5 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.
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.
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:
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.
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).
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)
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
<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>