• Resolved miloh

    (@bejita)


    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 VALUE1

    AND

    CUSTOM FIELD4 or CUSTOM FIELD5 LIKE VALUE2

    AND

    CUSTOM FIELD6 LIKE VALUE3

    VALUE1, VALUE2 AND VALUE3 are variables from ajax.

    • This topic was modified 3 years, 11 months ago by miloh.
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    @bejita Which variables are you trying to get from the ajax request?

    Are you getting data from the querystring?

    Thread Starter miloh

    (@bejita)

    @dcooney the data are from the front-end, typed in two innput textfields and selected from input select form.

    Plugin Author Darren Cooney

    (@dcooney)

    Sorry, I don’t understand. How are you planning to get these values inside the alm_query_args filter?

    Plugin Author Darren Cooney

    (@dcooney)

    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.

    Thread Starter miloh

    (@bejita)

    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 ?

    Plugin Author Darren Cooney

    (@dcooney)

    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.

    Thread Starter miloh

    (@bejita)

    Thank you for your response, I will try it

    Plugin Author Darren Cooney

    (@dcooney)

    @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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘how to add variable value to function alm_query_args_{id}’ is closed to new replies.