How to encode “post_type” in URL?

I stumbled upon this article –

Essetially it explains that you can do stuff like this:

With a bit of javascript you can make a non-AJAX filtering thing on your site pretty easily.

My question is how can you add to an URL a “post_type” parameter for custom posts?

I tried (example post type is “news”):

But it didn’t work.

When writing a wp_query, you would write something like this:

$query->set ( [‘post_type’ => ‘news’);

But I have to no idea how to put this in the URL.


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer