Forums › Forums › Search & Filter Pro › Execute ajax request using javascript?
Tagged: javascript
- This topic has 16 replies, 2 voices, and was last updated 8 years ago by Trevor.
-
Trevor(Private) October 29, 2016 at 10:06 am #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:
You would have to go back to existing posts/pages/etc to re-save them, but it would work.
Trevor(Private) October 29, 2016 at 10:54 am #67152Well, 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(Private) October 29, 2016 at 6:40 pm #67175One 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 );
-
AuthorPosts