How do I use URL to fetch all posts of a particular custom post type?

I think what you mean is do an onclick event.

So, you can do this with JavaScript. Create your link as per usual <a id=“myCustomLink” href=“#” onclick=“MyFunction();return false;”>huh! I’m a link!</a>

And now some script

<script>
function MyFunction() {

//Make it do whatever here! For example:

document.getElementById("demo").innerHTML = "Hello World";
}
</script>

Rerun false; will prevent the browser directing to the link… unless you want it to? If so then just remove this and add a link in-place of the # after the href.

However! A much cleaner way of doing this would be to do it as JQuery and attach the ID as an onclick handler. Like so:

$(‘#myLink’).click(function(){ MyFunction(); return false; });

Hope this helps!