Ajax Load More Logo
You may be required to access page level variables from the parent page/post inside an Ajax Load More Repeater Template. This sounds like a simple task, however page level variables will be undefined when being called from within an Ajax request.
To get around this limitation, Ajax Load More provides a vars parameter that can used to pass variables from a page template to a Repeater Template.
Note: The vars parameter is a semicolon separated list of key:value pairs. e.g. theme:red;show_image:false
In the following example, page level variables are being defined in the page template and passed to Ajax Load More via the vars shortcode parameter. Variables are then accessed from the $args array in the Repeater Template.
In the page template, before the [ajax_load_more] shortcode we define page variables and then pass the variables to Ajax Load More via the vars shortcode parameter.
Warning: Do NOT pass variables that contain sensitive data! All variables passed to Ajax Load More using the vars parameter are printed into the HTML output and can be read in the page source.
By default, Repeater Templates have access to an $args array that contains query data and other Ajax Load More related information. Variables passed from the page template using the vars parameter can be accessed under the alm_vars array key as shown below.
When passing variables using the vars parameter, the returned $args array will look something like the following code sample. Notice the alm_vars key – this array key contains the variable data that was passed to Ajax Load More.
Pro Tip: You can access the same $args and variable data when using the alm_query_args hook.
« Back to Code Samples