Using query strings to filter topic views

:bookmark: This guide explains how to use query strings to get custom filtered topic views on any Discourse site. Query strings can be used by all users to view specific lists of topics, create custom links to unique topic lists, and search for topics meeting specific criteria.

:person_raising_hand: Required user level: All users

Query strings are text that you can append to the end of most Discourse URLs to get a custom, filtered view of topics. They can be useful for viewing specific lists of topics, creating custom links to unique topic lists, and searching for topics that meet specific criteria.

Understanding query strings

A query string is added to the end of a URL, starting with a question mark (?), followed by parameters and their values. For example:

https://meta.discourse.org/?status=open

In this URL, ?status=open is the query string.

The list of topics you see when using query strings will still be limited to the topics accessible by your user account. No settings need to be enabled to use query strings.

Available query string parameters

Here are the query string parameters you can use on all Discourse sites:

Status

Use ?status=_ to display topics with a specific status:

  • open: Open topics only
  • closed: Closed topics only
  • archived: Archived topics only
  • unlisted: Unlisted topics only
  • deleted: Deleted topics only

Search

Use ?search=_ to create a full page of search results. Replace _ with your search terms.

State

Use ?state=_ to display topics with a specific state:

  • muted: Show topics you’ve muted
  • normal: Show topics you have set to normal
  • tracking: Show topics you’re tracking
  • watching: Show topics you’re watching

Ascending order

Use ?ascending=true to show topics by date in ascending order. The default is descending order.

Order

Use ?order=_ to display topics in descending order by various criteria:

  • likes: By like count
  • op_likes: By likes on the original post
  • views: By views
  • posts: By post count (replies)
  • activity: By last activity date (includes bumped_at date)
  • posters: By the number of participants
  • category: By category name (Z-A)
  • created: By topic creation date (newest topics first)

Post count filters

  • ?max_posts=_: Returns topics with post counts of _ or lower
  • ?min_posts=_: Returns topics with post counts of _ or greater

Topic IDs

Use ?topic_ids=_ to display a list of topics with specific IDs. Accepts a comma-delimited string of topic IDs.

Category

Use ?category=_ to display a list of topics for specific categories. Accepts a comma-delimited string of category ID numbers.

Tags

Use ?tags=_ to filter topics by tags. For example, https://meta.discourse.org/?tags=how-to would show all topics with the how-to tag.

Plugin-specific parameters

Some plugins add additional query string parameters:

Solved plugin

If you have the Solved plugin installed:

  • ?solved=yes: Show solved topics
  • ?solved=no: Show unsolved topics

Assign plugin

If you have the Assign plugin installed:

  • ?assigned=username: View all assigned topics for a specific user
  • ?assigned=*: View all assigned topics for all users
  • ?assigned=me: View all topics assigned to the current user
  • ?assigned=nobody: View all unassigned topics

Combining query strings

You can combine multiple query strings using the ampersand (&) symbol. When using multiple query strings, only the first parameter needs the ? symbol. For example:

https://meta.discourse.org/?max_posts=1&status=closed

This URL would show closed topics with only one post.

Using the advanced search page

You can also use the advanced search page to build these URLs with a graphical user interface and then copy the resulting URL. Note that some search filters may not work as query string parameters outside of the search context.

Additional resources

Last edited by @hugh 2024-07-02T09:58:50Z

Last checked by @hugh 2024-07-02T09:58:55Z

Check documentPerform check on document:
18 Likes

Can’t you use the advanced search page to build these urls with the gui and then just copy the url?

1 Like

It seems they are the same parameters (we just need to replace : from the search filter to = in the query string), but some search filter doesn’t work when used as a query string parameter outside search.

So I believe the full list is in this documentation. I’d be curious to see in which Discourse file they are referenced to be sure, though.

Edit : there is now a /filter route with way more filter criteria:

3 Likes

If you have the Solved plugin, you can also use:

?solved=yes
?solved=no

3 Likes

I think there are some for Assign too:

I’ll add them in. :+1:

3 Likes

At a guess imagine you could also use this for Tags?

Awesome how to

2 Likes

Yes, you can append ?tags=_ to Discourse URLs use query strings to filter for tags.

For example, https://meta.discourse.org/?tags=how-to would direct you to all of the how-to tags on Meta.

2 Likes

Is is possible to have a negative (exclude) filter using query string ? Currently with the advanced search it is done by prefix with a -

-tags: smth but this is not possible with query string.

It is definitely possible by using the new /filter route.

For example https://meta.discourse.org/filter?q=-tags%3Aofficial%20%20category%3Aplugin

2 Likes

Tks ! How about search with multiple status (OR) ? I tried different way of searching but it seems that’s not supported at all. For example I have some topics that are either open, closed or archived, I just want to filter out the archived, aka search for open OR closed. So far I tried

  • Advanced search: status:open,closed
  • Advanced search: status:open status:closed
  • Query string: ?status=open,closed

None of them works.