Unable to use “custom_args” or “vars” from front-end JavaScript
-
When working with with the public
ajaxloadmore.filter()
function on the front-end of a theme, there appears to be a bug that is preventing the use ofcustom_args
andvars
.The following steps should allow for reproduction of the issue:
- Enable debug mode in your theme’s
functions.php
file:add_filter( 'alm_debug', '__return_true' );
- Add
alm_render()
to a page template. - On the front-end of a site, navigate to a page where the modified template is in use.
- From the browser console, manually trigger the
filter()
method on the globalajaxloadmore
instance:ajaxloadmore.filter('fade', 250, {customArgs: 'foo:bar;biz:bash'})
- In the browser’s network tab, inspect the payload that was sent:
action: alm_get_posts query_type: standard id: post_id: 123 slug: your-page canonical_url: https://your-test-site.example/ posts_per_page: 5 page: 0 offset: 0 post_type: post repeater: default seo_start_page: 1 order: DESC orderby: date custom_args: foo%3Abar%3Bbiz%3Abash
Also in the network tab, inspect the preview of the response that was sent:
{ "meta": { "postcount": 5, "totalposts": 245, "debug": { "post_type": [ "post" ], "posts_per_page": "5", "offset": 0, "order": "DESC", "orderby": "date", "post_status": "publish", "ignore_sticky_posts": true, "foo%3Abar%3Bbiz%3Abash": null, "alm_id": "", "paged": 1, "alm_query": "alm" } } }
The payload shows that the data is being escaped before it has been sent, which is then preventing the parsing functions of the plugin from correctly reading the
custom_args
data. The plugin tries to split thecustom_args
data into key values pairs on semicolons and colons, but since those characters were escaped prior to being sent to Admin Ajax for handling, they are never read properly. - Enable debug mode in your theme’s
- The topic ‘Unable to use “custom_args” or “vars” from front-end JavaScript’ is closed to new replies.