{"id":21982,"date":"2021-07-29T11:18:42","date_gmt":"2021-07-29T11:18:42","guid":{"rendered":"https:\/\/unlimited-elements.com\/?post_type=docs&#038;p=21982"},"modified":"2024-02-04T09:40:36","modified_gmt":"2024-02-04T09:40:36","password":"","slug":"current-query-posts","status":"publish","type":"docs","link":"https:\/\/unlimited-elements.com\/docs\/current-query-posts\/","title":{"rendered":"Current Query Posts Custom Filters"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"21982\" class=\"elementor elementor-21982\" data-elementor-post-type=\"docs\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f405db5 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f405db5\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3bbc772\" data-id=\"3bbc772\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-8f48f48 elementor-widget elementor-widget-text-editor\" data-id=\"8f48f48\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><b>Current Query Posts<\/b> &#8211; This type works only when the widget is inside of an archive template. It shows the current posts which are being used in the archive page.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-01a766a elementor-widget elementor-widget-text-editor\" data-id=\"01a766a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>To create custom filters not available in the settings using php code. You can assign the post list a\u00a0<strong>Query ID<\/strong>\u00a0(this feature is only available\u00a0in the the pro version of unlimited elements)<br \/>Using the Query ID feature you have unlimited possibilities\u00a0to select your posts.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-628f48e elementor-widget elementor-widget-text-editor\" data-id=\"628f48e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Instructions how to use the query ID filter:\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a737021 elementor-widget elementor-widget-text-editor\" data-id=\"a737021\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In the widget you set the query ID to\u00a0<strong>my_query_filter<\/strong><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-baa9df6 elementor-widget elementor-widget-image\" data-id=\"baa9df6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"800\" height=\"244\" src=\"https:\/\/unlimited-elements.com\/wp-content\/uploads\/2021\/07\/my_query_filter.jpg\" class=\"attachment-large size-large wp-image-21988\" alt=\"\" srcset=\"https:\/\/unlimited-elements.com\/wp-content\/uploads\/2021\/07\/my_query_filter.jpg 900w, https:\/\/unlimited-elements.com\/wp-content\/uploads\/2021\/07\/my_query_filter-300x91.jpg 300w, https:\/\/unlimited-elements.com\/wp-content\/uploads\/2021\/07\/my_query_filter-768x234.jpg 768w, https:\/\/unlimited-elements.com\/wp-content\/uploads\/2021\/07\/my_query_filter-600x183.jpg 600w\" sizes=\"(max-width: 800px) 100vw, 800px\" title=\"\">\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cb499cc elementor-widget elementor-widget-text-editor\" data-id=\"cb499cc\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>After that you go to your theme folder &#8211; functions.php file and add those lines:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c68b01d elementor-widget elementor-widget-code-highlight\" data-id=\"c68b01d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-javascript line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-javascript\">\n\t\t\t\t\t<xmp>\/*\n * filter the arguments to get my custom posts\n * args - original arguments\n * $widgetControlsValues - all the values of the current widget. \n * it can be used for the post list\n *\/\nfunction myQueryFilter($args, $widgetControlsValues){\n\t\n\t\/\/set filter to posts that published within 24 hours (today)\n\t$args['date_query'] = array(\n\t        'column'  => 'post_date',\n\t        'after'   => '-1 days'\n\t );\n\t\t\t\t\t\n\treturn($args);\n}\n\nadd_filter(\"my_query_filter\", \"myQueryFilter\", 10, 2);<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-11931eb elementor-widget elementor-widget-text-editor\" data-id=\"11931eb\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Another code example, with use of $widgetControlValues. For this example you create a dropdown attribute with those settings:\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-31931b4 elementor-widget elementor-widget-image\" data-id=\"31931b4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" width=\"800\" height=\"436\" src=\"https:\/\/unlimited-elements.com\/wp-content\/uploads\/2021\/07\/my_query_filter2.jpg\" class=\"attachment-large size-large wp-image-21998\" alt=\"\" srcset=\"https:\/\/unlimited-elements.com\/wp-content\/uploads\/2021\/07\/my_query_filter2.jpg 900w, https:\/\/unlimited-elements.com\/wp-content\/uploads\/2021\/07\/my_query_filter2-300x164.jpg 300w, https:\/\/unlimited-elements.com\/wp-content\/uploads\/2021\/07\/my_query_filter2-768x419.jpg 768w, https:\/\/unlimited-elements.com\/wp-content\/uploads\/2021\/07\/my_query_filter2-600x327.jpg 600w\" sizes=\"(max-width: 800px) 100vw, 800px\" title=\"\">\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cdf9a4d elementor-widget elementor-widget-text-editor\" data-id=\"cdf9a4d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Name: day, values: all, today, tomorrow. What we want is that if today chosen, it will filter posts only from today, and if yesterday chosen, it will filter posts from yesterday. So in functions.php you insert this code:\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bf7a3dc elementor-widget elementor-widget-code-highlight\" data-id=\"bf7a3dc\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-javascript line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-javascript\">\n\t\t\t\t\t<xmp>\/**\n * filter the arguments to get my custom posts\n * args - original arguments\n * $widgetControlsValues - all the values of the current widget. \n * it can be used for the post list\n *\/\nfunction myQueryFilter($args, $widgetControlsValues){\n\t\t\n\t$day = $widgetControlsValues[\"day\"];\n\t\n\tif($day == \"today\"){\n\t\t$args['date_query'] = array(\n\t        'column'  => 'post_date',\n\t        'after'   => '-1 days'\n\t    );\t\t\t\t\n\t    \n\t}\n\telse\n\tif($day == \"yesterday\"){\n\t\t\n\t\t$args['date_query'] = array(\n\t        'column'  => 'post_date',\n\t        'after'   => '-2 days',\n\t\t'before'  => '-1 days'\n\t    );\t\t\n\t}\n\t\n\t\n\treturn($args);\n}\nadd_filter(\"my_query_filter\", \"myQueryFilter\", 10, 2);\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2e0fe49 elementor-widget elementor-widget-text-editor\" data-id=\"2e0fe49\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Of course, you don&#8217;t have to put your code into functions.php, there are certain plugins that you can put php code snippets into without updating theme php files.\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-62d5342 elementor-widget elementor-widget-text-editor\" data-id=\"62d5342\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<article id=\"fullArticle\"><p>Plugin example:\u00a0<a href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\" target=\"_blank\" rel=\"noopener\">https:\/\/wordpress.org\/plugins\/code-snippets\/<\/a><\/p><\/article>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Current Query Posts &#8211; This type works only when the widget is inside of an archive template. It shows the current posts which are being used in the archive page. To create custom filters not available in the settings using php code. You can assign the post list a&nbsp;Query ID&nbsp;(this feature is only available&nbsp;in the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"doc_category":[63],"doc_tag":[],"class_list":["post-21982","docs","type-docs","status-publish","hentry","doc_category-advanced-post-selection"],"acf":[],"year_month":"2026-06","word_count":350,"total_views":"2159","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"Maxim Vendrov","author_nicename":"admin","author_url":"https:\/\/unlimited-elements.com\/author\/admin\/"},"doc_category_info":[{"term_name":"Advanced Post Query","term_url":"https:\/\/unlimited-elements.com\/docs-category\/advanced-post-selection\/"}],"doc_tag_info":[],"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/unlimited-elements.com\/wp-json\/wp\/v2\/docs\/21982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unlimited-elements.com\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/unlimited-elements.com\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/unlimited-elements.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unlimited-elements.com\/wp-json\/wp\/v2\/comments?post=21982"}],"version-history":[{"count":18,"href":"https:\/\/unlimited-elements.com\/wp-json\/wp\/v2\/docs\/21982\/revisions"}],"predecessor-version":[{"id":102523,"href":"https:\/\/unlimited-elements.com\/wp-json\/wp\/v2\/docs\/21982\/revisions\/102523"}],"wp:attachment":[{"href":"https:\/\/unlimited-elements.com\/wp-json\/wp\/v2\/media?parent=21982"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/unlimited-elements.com\/wp-json\/wp\/v2\/doc_category?post=21982"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/unlimited-elements.com\/wp-json\/wp\/v2\/doc_tag?post=21982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}