megclaypool
9/26/2018 - 7:54 AM

Using URL info to query in WordPress

[Using URL info to query in WordPress]

You can set links on your page to anchor to

In your template.php file, after you've set your standard arguments you can add some based on categories it picks out of the url

if (!empty($_GET['category'])) {
    $queryCategory = $_GET['category'];
    $args['category_name'] = $queryCategory;
}

Then just make sure to have links on your page that go to currentpage?category=some_slug

Then the filter will be added to your query arguments and the posts on the page will get filtered!

Note that the word category can be changed to anything; I was just using categories on my example :)