I have a html button which has an onclick method. The function which is ran onclick has a php function in but is called in JS, like below.
<script type="text/javascript">
function Test() {
<?php add_post_meta($post->ID, '_my_meta_key', true); ?>
}
</script>
<button onclick="Test()"></button>
The page this code is on is a wordpress admin page. When the page loads, the php function is ran anyway instead of waiting for the button click event. Is there a way to stop this from happening and only fire once the button is clicked.