How to get the parameter filter condition list of a specified document model?

Calendar 👁️ 65

In website operation, providing users with a convenient content filtering function can significantly improve user experience and content discovery efficiency.AnQi CMS provides powerful interfaces that allow us to flexibly obtain and utilize these filtering conditions.Today, let's discuss how to get the parameter filter condition list of the specified document model in Anqi CMS.

Understand the importance of filtering conditions

Imagine if your website has many products or articles, and users want to search based on dimensions such as 'city', 'education', or 'product type'.If each filter requires manual input of keywords, the efficiency will be very low.By providing a preset list of filtering conditions, the user can quickly locate the target content by clicking or selecting.These dynamic filtering conditions are the key to improving the interactivity and user-friendliness of the website.

AnQi CMS provides a dedicated interface for us to easily obtain these filter parameters, and then build richly functional filters on the frontend page.

The core interface to get the filtering conditions

To get the parameter filtering conditions list of the specified document model, we need to use AnQi CMS'sarchive/filtersInterface. This interface is designed specifically to retrieve the model's filtering fields and their corresponding options.

API call method

The calling address of this interface is very intuitive:

{域名地址}/api/archive/filters

Remember,{域名地址}Replace with your actual website domain, for examplehttps://en.anqicms.com/api/archive/filters.

This interface usesGETThe method is called, which means you only need to attach the necessary parameters to the request, and do not need to send data in the request body.

Core request parameters:moduleId

The most critical thing is to provide the filtering conditions for a specific document modelmoduleId.moduleIdRepresents the unique identifier of the document model you want to query.For example, the 'Article' model may have an ID (such as 1), and the 'Product' model may have another ID (such as 2).

  • How to obtainmoduleId?You can view the IDs of various models through the Anqi CMS backend or callmodule/listInterface to get the list of all models and their corresponding IDs.

When you initiate the request, just specify themoduleIdAttach as a query parameter to the URL. For example, if you want to get the filtering conditions of the document model with ID 1, the request example is as follows:

{域名地址}/api/archive/filters?moduleId=1

Interpretation of the interface returned data

Successfully calledarchive/filtersAfter the interface, you will receive a JSON formatted response.This response contains all the fields and their detailed information available under the document model.

{
  "code": 0,
  "data": [
    {
      "name": "城市",
      "field_name": "city",
      "items": [
        {
          "label": "全部",
          "total": 0
        },
        {
          "label": "北京",
          "total": 0
        },
        {
          "label": "上海",
          "total": 0
        }
      ]
    },
    {
      "name": "学历",
      "field_name": "certificate",
      "items": [
        {
          "label": "全部",
          "total": 0
        },
        {
          "label": "硕士",
          "total": 0
        },
        {
          "label": "本科",
          "total": 0
        }
      ]
    }
  ],
  "msg": ""
}

In the response ofdataThe field is an array, each element of which represents a filterable field. The structure of each filter field includes the following important parts:

  • name(string): This is the display name of the filter condition, for example, "City
  • field_name(string): This is the call name of the filter field, for example 'city', 'certificate'.This field is very importantbecause it is called after youarchive/listIt needs to be used as the key name of the request parameter when filtering the actual document list through the interface.
  • items(object[]): This is an array that contains all available parameter options for the current filter field. Each option also includes:
    • label(string): Display text of parameter options, such as “Beijing”, “Master”, “All”.
    • total(int): Theoretically represents the number of documents matched under the option.In the current document example, it is displayed as 0, which may indicate that the interface does not directly return the exact count under the filter conditions, or it may need to be effective under specific configurations.labelJust do it.

Apply the filter condition to the document list

After obtaining this list of filter conditions, you can dynamically generate filters on the website front-end. For example, you can create dropdown menus or checkbox groups for "City" and "Education.

When a user selects one or more options in a filter, you can usefield_nameandlabelthe value, combinedarchive/listthe interface to retrieve the list of matching documents.

For example, if the user selects "city" as "Beijing", you can send the following request toarchive/list:

{域名地址}/api/archive/list?moduleId=1&city=北京

HerecityExactlyarchive/filtersThe interface returnsfield_namewhile北京is the user's selectionlabelIn this way, users can perform multi-condition combination filtering, which greatly facilitates the exploration of content.

Tip

  • Background configuration is the foundation:Only when a custom field is set to 'filterable' in the document model of AnQi CMS backend, it will be displayed inarchive/filtersAn interface appears. If you find that some filtering conditions are missing, please check the backend model field configuration first.
  • Handling of the 'All' option: itemsusually contains an 'All' option.label. When the user selects 'All', it usually means that there is no filtering for this field, so it can be omitted when callingarchive/listit can be omittedfield_nameParameter.
  • field_namenaming conventions: field_nameIt is usually English or pinyin, used for interface calls, andnamewhich is Chinese or other languages, used for interface display.

Masterarchive/filtersThe use of the interface will enable you to build a more flexible and user-friendly content filtering feature for your safe CMS website, effectively enhancing the practicality and user experience of the website.


Frequently Asked Questions (FAQ)

1. Why do I callarchive/filtersthe interface returns?dataThe array is empty?This is usually due to the following reasons:

  • You providedmoduleIdIncorrect, or no filtering fields are configured under the model corresponding to this ID.
  • The document model has custom fields, but these fields are not checked as 'filterable' attributes in the model settings of the Anqi CMS backend.Please log in to the backend and check the field configuration of the corresponding model.

2.field_nameandnameWhat is the difference? Which one should I use? nameIs for user interface display, for example, displayed as "city", "education", which is more readable. Whilefield_nameIt is used for program internal identification and interface calls, for examplecity/certificateWhen you build a frontend filter, you need to send the user's selected conditions toarchive/listwhen usingfield_nameas the key for the request parameters.

3.itemsin.totalDoes the field always display as 0? Is this normal? What is its purpose?Based on the document example you provided,totalThe field is displayed as 0, which is normal. This may mean that in the current interface design,archive/filtersThe interface is mainly used to return a list of selectable options (i.e.,label) without real-time statistics of the number of documents under each option. When building the front-end filter, you mainly focus onlabelGenerate options as needed. If you need to display the number of documents under each filter condition, you may need to call the interface separatelyarchive/listand combine it with different filter conditions to count.

Related articles

How to optimize the navigation experience of the previous and next documents through the `archivePrev` and `archiveNext` interfaces?

Today, with the increasing refinement of content management, every detail of a website may affect the reading experience of users.Among them, the navigation between the previous and next documents, as an important part of guiding users to continuously explore the website content, should not be overlooked in terms of convenience and fluidity.AnQiCMS (AnQiCMS) knows this and provides the powerful and intuitive interfaces `archivePrev` and `archiveNext` to help us easily implement and optimize this feature.###

2025-11-09

How should the comment area on the document detail page be integrated with the Anqi CMS comment API to display and publish comments?

In website operation, the comment area of the document detail page plays an important role, it not only promotes user interaction and enhances content activity, but also brings new content and search engine visibility to the website.AnQiCMS provides a powerful and easy-to-integrate comment API that allows you to easily implement comment display and posting features on your website.This article will discuss in detail how to use these APIs to create a fully functional comment system for your document detail page.##

2025-11-09

How to implement reading level control for specific documents (such as paid documents) in Anqi CMS?

In AnQi CMS, implementing a reading level control (`read_level`) for specific documents (such as paid documents or exclusive member content) is a very practical feature. It helps us better manage content permissions and achieve differentiated content operations.This mechanism is not only flexible, but also closely integrated with the user system, allowing us to determine what content users can see based on their identity or payment status. Next, we will explore how to efficiently use `read_level` in Anqi CMS to implement document access control.###

2025-11-09

How to query all custom field information contained in a model (such as an article model)?

The Anqi CMS, with its powerful content model and flexible custom field features, provides great convenience for website operators.These custom fields are the key to the personalization and data structuring of website content.How can you accurately query all the custom field information contained in a specific model (such as an article model)?This is very useful when performing secondary development, data connection, or just to understand the system structure.

2025-11-09

In AnQi CMS, what is the role of the `moduleId` parameter in the `archiveFilters` interface?

When using AnQiCMS to build a website, we often need to provide flexible filtering functions for different types of content so that visitors can quickly find the information they need according to their needs.The `archiveFilters` interface was born for this purpose, it can help us get the document filtering conditions.And in this interface, the `moduleId` parameter plays a crucial role.### `archiveFilters` interface's `moduleId`

2025-11-09

What do the `name` and `field_name` in the `archiveFilters` interface represent?

During the development and content management process of Anqi CMS, we often need to handle document filtering and display.The `archiveFilters` interface was born for this purpose, it provides the ability to dynamically obtain filtering conditions.Understand the `name` and `field_name` fields in the returned data, which are crucial for building flexible and versatile front-end filtering functions.

2025-11-09

How to interpret the `items` array in the filtering conditions API, used to build the front-end filter?

In modern web design, the content filtering feature has become an important part of improving user experience and content discoverability.A well-designed filter can help users quickly locate the information they are interested in, whether it is products, articles, or any other form of content.For Anqi CMS, the provided filtering conditions API (/api/archive/filters) is the foundation for building such frontend filtering functions.Especially the `items` array in the response data is the key to understanding and implementing dynamic filtering.

2025-11-09

Why does the `total` field often display as 0 in the `archiveFilters` returned data? What is its real purpose?

When using AnQi CMS for website content management, we often deal with various API interfaces.Among them, the `archiveFilters` interface is an important tool for obtaining document filtering conditions.Many users notice that when using this interface, the `total` field in the `items` list of the returned data always displays as `0` for each filter option (such as `Beijing` and `Shanghai` under `City`).This may be confusing: Since it's a 'quantity', why is it `0`? This

2025-11-09