Support » Plugin: WordPress Infinite Scroll - Ajax Load More » how to add variable value to function alm_query_args_{id}
how to add variable value to function alm_query_args_{id}
-
Hello,
I have meta-key multiple relation OR/AND meta_query request and think to use filter alm_query_args_{id}, but my probelm is that my valueS query are not fixed values but a variables from ajax request. So how can I call the variables in the filter please ?
My request meta-query looks like :
CUSTOM FIELD1 or CUSTOM FIELD2 or CUSTOM FIELD3 LIKE VALUE1AND
CUSTOM FIELD4 or CUSTOM FIELD5 LIKE VALUE2
AND
CUSTOM FIELD6 LIKE VALUE3
VALUE1, VALUE2 AND VALUE3 are variables from ajax.
-
This topic was modified 2 months ago by
miloh.
-
This topic was modified 2 months ago by
-
@bejita Which variables are you trying to get from the ajax request?
Are you getting data from the querystring?
@dcooney the data are from the front-end, typed in two innput textfields and selected from input select form.
Sorry, I don’t understand. How are you planning to get these values inside the
alm_query_args
filter?If you know the variables, you could piece together a dynamic shortcode based on those values, rather than trying to access them during the Ajax request.
That said, in the next version of Ajax Load More I’ve built a solution for passing variables to the Repeater Templates and the
alm_query_args
filter.For example`
function my_movie_listing($args, $id){ $args['post_type'] = 'movie'; $args['meta_query'] = array( array( 'key' => 'custom-field1', 'value' => $value1, 'compare' => 'LIKE' ) ); return $args; } add_filter( 'alm_query_args_movie_listing', 'my_movie_listing', 10, 2);
The $value1 is not a fixed value but data from form, and that’s the question, how can I set this value. How can I make dynamic shortcode based on those values, is there a documentation ?
No docs, but a most basic example would be as follows.
$variable = 'my input value'; $customfields = ''; if ( $variable ) { $customfields = ' meta_key="custom-field1" meta_value="' . $variable . '" meta_compare="LIKE"'; } echo do_shortcode( '[ajax_load_more post_type="movie"' . $customfields . ']' );
Obviously, if you have more than one variable you need to string them together.
Thank you for your response, I will try it
@bejita
Here is an updated method of passing variables to a Repeater Template or Filter.
https://connekthq.com/plugins/ajax-load-more/docs/code-samples/passing-variables/You can use the
vars
param and access it in the$args
of the hook.
- You must be logged in to reply to this topic.