1

I create my action in functions.php

add_action('wp_ajax_myfilter', 'misha_filter_function'); // wp_ajax_{ACTION HERE} 
 function misha_filter_function()
 {
   echo "my button action"; 
 }

How can i create button to call this method wp_ajax_myfilter

1 Answer 1

1

Try below method.

<a id="view_site_description" href="javascript:void(0);">View Our Site Description</a>

add_action( 'wp_footer', 'add_js_to_wp_footer' );
function add_js_to_wp_footer(){ ?>
    <script type="text/javascript">
    jQuery('#view_site_description').click(function(){
        jQuery.ajax({
            type: 'POST',
            url: ajaxurl,
            data: {"action": "myfilter"},
            success: function(data){alert(data);}
        });
        return false;
    });
    </script>
<?php }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.