Introduction
In Drupal Views, you can apply filters to display only results that match specific criteria—for example, content type = “Standard Page” and published = “Yes.” You can also expose these filters so that users are able to adjust them.

A contextual filter is a specific type of filter that derives its criteria dynamically from the surrounding context. Unlike regular filters, which use either a fixed criterion defined when the view is built or an exposed filter provided by user input, a contextual filter adapts based on external context. Most commonly, this context comes from the URL, but it can also originate from other sources, such as the logged-in user’s ID.

Examples
Example-1: Contextual Filter by Author UID (provided in URL)
Below is a example of view using contextual filter to only show content authored by certain user (uid provided via the URL):

Example-2: Contextual Filter by Author UID (logged in user)
If you prefer not to supply contextual filter criteria or values through the URL path (for instance, when the view is a block not a page), you can select “Provide default value” under “When the filter value is NOT available.” This option offers additional methods for specifying the criteria or values for contextual filters.

Below are the available options to be context for contextual filter :
Fixed : fixed value
Time/Date Related
- Current date
- Current node ‘changed’ time
- Current node ‘created’ time
From URL ==(not recommended if you will be using URL alias for page)==
- Content ID from URL
- Raw value from URL
- Taxonomy term ID from URL
User ID
- User ID from logged in user
- User ID from route context (if visiting
/user/idpage OR its aliased page)
Query Parameter
- For instance: url
https://example.com/search?name=simon.hu&age=18have the following query parameter:name=simon.huage=18
- For instance: url
Example-2a
For instance, I could set the “default value” for a view block’s contextual filter to be “User ID from route context”, then add it to be only visible on the “/user/*” page; The view block can then automatically filter pages based on the user page:

(*note that: after the change the block is only showing the pages created by the particular user)
Example-2b
Here’s another example, , I could also set the “default value” for a view block’s contextual filter to be “Query Parameter”, then on any page I can provide the contextual filtering criteria after ? question mark:

(*note that: after the change page with URL of ?username= query parameter becomes different)
Example-3: Contextual Filter with Title Override
Sometimes it is good to have some indication over what is the current contextual filter in use, this is where the “title override” feature may come in handy, when a contextual filter value is detected, you can use twig syntax to customise the title based on the criteria given (you can find the available twig variables from the “replacement patterns” drop down):

Example-4: Contextual Filter + Relationships
If you wish to filter by fields that are not by default available in the view’s primary entity (for instance, “user’s email” in “node” entity type), you could use relationship feature. For instance, we could add relationship of “User” to the “Node” view, to make the user’s name, email available for contextual filtering:

Reference & Extension Reading
- WebWash - 5.31 - Use Contextual Filter in View: link
- Drupal Official Documentation: