I am trying to modify the display of the views-filter checkboxes used in a parametric search. I've written a WordPress 'do_shortcode_tag' filter for the 'wpv-control-post-taxonomy' shortcode. It works on initial load and full page refresh. When the results are updated via AJAX -- when an input is changed (checkbox checked/unchecked) -- the new results are not run through the filter.
How can I get my filter to run on AJAX updates as well as full page loads?
add_filter( 'do_shortcode_tag', 'bcaccs_add_checkbox_classes', 99, 4);
function bcaccs_add_checkbox_classes( $content, $tag, $attr, $m ) {
file_put_contents('shortcodes.txt', date('r') . " $tag\n", FILE_APPEND);
if ($tag == 'wpv-control-post-taxonomy' && $content != '') {
if ($attr['taxonomy'] == 'topic' && $attr['type'] == 'checkboxes' && $attr['url_param'] == 'wpv-topic') {
// Do stuff
}
}
return $content;
}
Hello,
It is a custom codes problem, I have tried your PHP codes in my localhost it works fine, you can not output result in the custom PHP function, but you can change the result, for example:
add_filter( 'do_shortcode_tag', 'bcaccs_add_checkbox_classes', 99, 4);
function bcaccs_add_checkbox_classes( $content, $tag, $attr, $m ) {
file_put_contents('shortcodes.txt', date('r') . " $tag\n", FILE_APPEND);
if ($tag == 'wpv-control-post-taxonomy' && $content != '') {
if ($attr['taxonomy'] == 'topic' && $attr['type'] == 'checkboxes' && $attr['url_param'] == 'wpv-topic') {
// Do stuff
$content .= 'Append some test text here ... ';
}
}
return $content;
}
And if you need to add some CSS class to the taxonomy checkboxes field, you can try to add attribute "class" to the shortcode [wpv-control-post-taxonomy], for example:
[wpv-control-post-taxonomy class="my-class" ...]
More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-control-post-taxonomy
class (opt):
'class names separated by space'
You have missed my question.
- I have working code
(the code snippet was intended to make the filter clear, and is not the actual code)
- The code is executed correctly on a full page load
- The code is NOT executed when the filter checkboxes are updated via AJAX
(For example: When a user clicks a filter checkbox and the view results are updated)
.
How can I make the search view execute my code for both a standard page load and a AJAX update load?
I am using a hierarchical taxonomy and need to assign parent/child classes to the term checkboxes based on their relationship. I do not see a short code option that does this.
As I mentioned above, I have tested your PHP codes in my localhost, it works fine:
the search view execute your code for both a standard page load and a AJAX update load
With below steps:
1) Modify the PHP codes as below:
https://toolset.com/forums/topic/ajax-update-on-parametric-search-not-running-shortcodes/#post-905309
2) Test the view with AJAX search form, I can see the text after change the "topic" filter checkboxes:
Append some test text here ...
If you still need assistance for it, please provide a test site with the same problem, fill below private detail box with login details and FTP access, also point out the problem page URL, and where I can edit you PHP codes, I can setup a demo for you.
OK, I see that the filter is being run during an AJAX call.
I was using file_put_contents() to write a debug file and tailing the file to troubleshoot. Regular page loads output the file to the WordPress root directory. AJAX page calls output the file to '/wp-admin'. That's why I wasn't seeing results and thinking the filters hadn't ran.
My code wasn't working because I'm using get_query_var( 'wpv-topic' ) to get information about page state. This does not exist on the AJAX call.
I also found in my research that WordPress considers the do_shortcode_tag filter private and it should not be used by outside of core. I need to rethink my approach.
Thanks for your help.