Get posts from taxonomy URL

So I’m taking some liberties with this, I’m assuming a couple things:

  1. You know the taxonomy the term belongs to
  2. You have the term archive link

So if I have the term archive link:

$url="http://www.example.com/taxonomy/term/";

I know that the last part of that url is going to be the terms slug. I can use the slug with the taxonomy and get the ID but first I need to split the parts:

$parts = explode("https://wordpress.stackexchange.com/", rtrim($url, "https://wordpress.stackexchange.com/")); // rtrim() to remove trailing slash

This splits it up in a nice array that looks like this:

Array ( 
    [0] => http: 
    [1] => 
    [2] => www.example.com
    [3] => taxonomy 
    [4] => term 
)

Note that the term slug is the last item in this array, which is important so we can access it later without really knowing the index.

Next we can use the nifty function called get_term_by() – View Codex, which will allow us to pull the entire term based on the terms slug and the taxonomy the term is in. which looks like this:

$term = get_term_by('slug', $parts[count($parts)-1], 'tax_articles');

And there you go, that will pull the term based off the slug we found in the URL.