Skip Navigation

[Resolved] Rerun shortcode on AJAX page load

This support ticket is created 7 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/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by Farrel 7 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#486434

Hi

I have this shortcode in my View to display the current term name. This is the code.

function display_term( $atts, $content ) {
$current_category = single_cat_title("", false);
return $current_category;
	}
add_shortcode('display-term-name', 'display_term');

When the page initially loads it works fine. The problem is when I use AJAX filtering on the results the results will refresh but the shortcode no longer displays anything.

I changed the 'return' to use 'echo' and the name stays, the problem with using 'echo' in a shortcode is that the text does not appear in the correct place so you have to use 'return'.

How can I fix it so that when the AJAX action takes place it refreshes the shortcode too and the term name stays?

Thanks

#486509

Dear Farrel,

There is a shortcode within Views plugin can etrieve archive title:
[wpv-archive-title], I suggest you use it to replace the custom shortcode you created, and test again
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-archive-title

#486647
cadoc.jpg

That is exactly what I did before and I had the same problem occurring. I then created my own shortcode thinking I could overcome that issue, but it was the same.

Try it yourself. Put the code inside the filter container like this and then you will see that whenever the results are refreshed it does not show anymore. You will see that the State (or whatever term it is) will no longer show.

#486880

I just tested it in my localhost with latest Views plugin in a fresh wordpress installation, the shortcode [wpv-archive-title] works fine, I suggest you check these in your website:
1) you are using the latest version of Views plugin
2) deactivate other plugins and switch to wordpress default theme, and test again

#486935

Just to confirm. Did you set the filtering of posts to be refreshed by AJAX whenever a dropdown field value is changed?

Did you then test this by changing the filter values so the results refresh without the page itself reloading?

#486947

This is the issue. If you put the shortcode like this it does work.

[wpv-archive-title]
[wpv-filter-meta-html]
[wpv-layout-meta-html]

But if you put the shortcode inside the filter block itself it does not work. Copy this to your view, change the filtering, and see for yourself.

[wpv-filter-start hide="false"]
<div class="filter-bar"><span class="filter-title"><a href="">[wpv-archive-title]</a> Doctors</span>
  
<div class="filter-treatment"> [wpml-string context="wpv-views"][/wpml-string] [wpv-control taxonomy="pa_treatments" url_param="wpv-pa_treatments" type="select" default_label="Treatment Options"][wpv-filter-spinner container="div" position="after" class="filter-spinner" spinner="/wp-content/plugins/wp-views/embedded/res/img/ajax-loader2.gif"][/wpv-filter-spinner][wpv-filter-reset reset_label="RESET" class="reset-button" style="butstyle" type="input"]</div>
</div>
[wpv-filter-end]
#486948

Ok I found the solution. I moved the [wpv-filter-start hide="false"] to begin after the [wpv-archive-title]. Now I just have to fix the CSS.

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