Skip Navigation

[Resolved] Return value from shortcode is static (cached?)

This support ticket is created 3 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 3 replies, has 3 voices.

Last updated by Waqar 3 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#2200547

From inside a view I'm calling a php function, which should return a dynamic value. However, the returned value is always the same, which is equal to the values returned the first time after I've changed the views setting. The shortcode works fine, when called from a shortcode block outside the view.

View:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop> 
			[get_url_parameter 'select']<br />
		</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		[wpml-string context="wpv-views"]No items found[/wpml-string]
	[/wpv-no-items-found]
[wpv-layout-end]

Shortcode (random number output just for testing):

add_shortcode('get_url_parameter', 'get_url_parameter_func');
function get_url_parameter_func ($attr) {
	return rand(0, 10);
}

How can I make the returned value dynamic?
Thanks in advance 🙂

#2200717

Nigel
Supporter

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

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

Screenshot 2021-10-20 at 14.15.48.png

I can't account for that, I don't get the same when I create a custom shortcode to return a random number on my own site (screenshot: in the loop I output the post title and then the random shortcode; the results are different for each iteration).

I suggest you try this after deactivating all non-Toolset plugins, perhaps something is interfering (although it is not obvious how).

I don't think it is related, but you don't name the attribute you are passing, you pass "select" rather than something like some-attribute="select".

Note that Views has a shortcode for retrieving url parameters: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-search-term

#2204769

Hi Nigel. Thank you for your answer 🙂
I'll look into your suggestions and see if any of them will help …
And thanks for the hint about shortcode for retrieving url parameters, which I didn't find although I looked for it 😉

#2205041

Thanks for the update and let us know if you have any follow-up questions.

For a new question or concern, you're welcome to start a new ticket.