Просмотр новости

Найдите то, что Вас интересует

Question about filtering default post categories with CS Forms

Дата публикации: 22-06-2026 17:29:23

Hey John,
This is possible without any custom PHP coding or custom taxonomies.
WordPress has native support for querying posts by their publish dates using the date_query parameter in WP_Query. Because Cornerstone’s Custom Query Builder parses Twig, you can conditionally build a date_query that handles year and month parameters (even when they contain multiple selected checkbox values).
Here is how you can set it up:
1. The Custom JSON for Query Builder
Modify your Custom JSON in the Query Builder to use date_query. WordPress’s date_query natively accepts arrays of numbers for year and month, which is perfect for multiple checkboxes:
SAMPLE BELOW:
{
"post_type": "post",
"cat": {{ url.param({"key":"post-category"}) | json_encode }},
"s": "{{ url.param({"key":"search"}) }}"
{% set year_param = url.param({"key":"post-year"}) %}
{% set month_param = url.param({"key":"post-month"}) %}
{% if year_param or month_param %}
, "date_query": [
{
{% if year_param %} "year": {{ year_param | json_encode }} {% endif %}
{% if year_param and month_param %}, {% endif %}
{% if month_param %} "month": {{ month_param | json_encode }} {% endif %}
}
]
{% endif %}
}
2. How to Set Up the Checkbox List Options
For the filters to work, the values of the options in your Checkbox Lists must match what WordPress expects for dates:
For the Year Checkbox List:
The value of each checkbox option must be a 4-digit year (e.g., 2024, 2025, 2026).
For the Month Checkbox List:
The value of each checkbox option must be the numerical representation of the month (e.g., 1 for January, 2 for February … 12 for December).
How this works for site editors:
Site editors do not need to do anything extra. They simply publish the post normally.
WordPress automatically extracts the year and month from the native post.publish_date and performs the comparison under the hood against the selected checkbox values.

Схожие новости

#Наименование новостиТональностьИнформативностьдата
1Question about filtering default post categories with CS Forms0022-06-2026
2Question about filtering default post categories with CS Forms0021-06-2026
3Question about filtering default post categories with CS Forms0022-06-2026
4Taxonomy Term redirect to filterable Post Type Archive0022-06-2026
5CS Forms & Off Canvas0022-06-2026
6Question about filtering default post categories with CS Forms0021-06-2026
7Taxonomy Term redirect to filterable Post Type Archive0022-06-2026
8Taxonomy Term redirect to filterable Post Type Archive0022-06-2026
9Accessibility Question0021-06-2026
10Need help setting up a looper of products that have an ACF Post Object selected0022-06-2026

Классификация: Общество. Схожих патентов: 0. Схожих новостей: 10. Тональность: 0. Информативность: 0. Источник: theme.co.