Forums Forums Search & Filter Pro Execute ajax request using javascript?

Tagged: 

Viewing 7 posts - 11 through 17 (of 17 total)
  • Anonymous
    #67145

    the same ‘search’?
    If you mean search form or query itself, I think so.
    I just need to request certain post_id to show single data on Search&Filter result area.

    Trevor
    #67147

    Which is why you want to be able to have a form field with the post_id. Thinking slightly out of the box, why not have a custom ACF field that contains the post ID, then you could have that in the form. You could easily set it to autopopulate as you save a post, as shown here:

    https://support.advancedcustomfields.com/forums/topic/how-to-create-a-calculated-acf-field-saved-in-the-db/

    You would have to go back to existing posts/pages/etc to re-save them, but it would work.

    Anonymous
    #67150

    I see, set post_id to custom field.

    Then how do I submit parameter from buttons?

    Trevor
    #67152

    Well, if you have a hidden form on the page, you can use javascript to change the value on the form when the user clicks the button, and that you could then have to auto submit the form using ajax.

    Let us assume that the Search & Filter form has a simple input field with the name _sf_my_post_id[]

    Load something like this to your page as an enqueued external asset:

    (function ( $ ) {
      "use strict";
      function changePostID(mypostid) {
        jQuery('input[name='_sf_my_post_id[]']').innerHTML = mypostid;
      }
    }(jQuery));

    And then, the button:

    <button onclick="changePostID('11')" id="button1">Change to Post 11</button>
    

    I am not sure if the javascript would also have to trigger the change flag on the input field

    But, if you tried this with the form visible, you would see if it worked, as a test

    Anonymous
    #67154

    Thank you!
    I’ll try this.

    Anonymous
    #67175

    One more question.
    Is there way to add extra parameter to shortcode?
    To set default query.

    i.e.

    [searchandfilter id="1428" show="results" post="123"]
    
    function sf_filter_query_args( $query_args, $sfid ) {
      if($sfid==1428)
      {
            /* i'm not sure how to get $shortcode_param */
      	$query_args['my_post_id'] = $shortcode_param['post'];
      }
      return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'sf_filter_query_args', 10, 2 );
    Trevor
    #67195

    I do not think so, no.

Viewing 7 posts - 11 through 17 (of 17 total)