{"id":7271,"date":"2024-03-20T18:15:43","date_gmt":"2024-03-20T07:15:43","guid":{"rendered":"https:\/\/brickslabs.com\/?p=7271"},"modified":"2024-09-26T21:34:25","modified_gmt":"2024-09-26T11:34:25","slug":"prefiltering-bricks-terms-query-loop","status":"publish","type":"post","link":"https:\/\/brickslabs.com\/prefiltering-bricks-terms-query-loop\/","title":{"rendered":"Prefiltering Bricks Terms Query Loop"},"content":{"rendered":"<div class=\"mp_wrapper\">\n  <div class=\"mepr-unauthorized-excerpt\">\n    <p>Let's say there's a Events CPT with a 'Event Year' custom taxonomy.<\/p>\n<p>Sample event year names could be: 2021, 2022, 2024, 2025, 2028 etc.<\/p>\n<p>We can set up a Terms query in <a href=\"https:\/\/brickslabs.com\/go\/bricks\" target=\"_blank\" rel=\"noreferrer noopener\">Bricks<\/a> to output these terms.<\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img src=\"https:\/\/brickslabs.com\/wp-content\/uploads\/2024\/03\/terms-bricks-query-loop.png\" alt=\"\" class=\"wp-image-7274\" \/><\/figure>\n<p>Result:<\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img src=\"https:\/\/brickslabs.com\/wp-content\/uploads\/2024\/03\/CleanShot-2024-03-20-at-6\u202f.04.34@2x.png\" alt=\"\" class=\"wp-image-7275\" \/><\/figure>\n<p>The reason 2021 is not present is because there are no posts that have been categorized with 2021.<\/p>\n<p>Now the requirement is to output only the (non-empty) years that are in the future.<\/p>\n<p>Like this:<\/p>\n<figure class=\"wp-block-image size-full is-resized\"><img src=\"https:\/\/brickslabs.com\/wp-content\/uploads\/2024\/03\/CleanShot-2024-03-20-at-6\u202f.07.53@2x.png\" alt=\"\" class=\"wp-image-7276\" \/><\/figure>\n<p>This <a href=\"https:\/\/brickslabs.com\/pro-tutorial\" target=\"_blank\" rel=\"noreferrer noopener\">Pro tutorial<\/a> shows how terms can be filtered based on their value using the <a href=\"https:\/\/academy.bricksbuilder.io\/article\/filter-bricks-terms-query_vars\/\" target=\"_blank\" rel=\"noreferrer noopener\">bricks\/terms\/query_vars<\/a> filter.<\/p>\n<p>Add the following in <a href=\"https:\/\/brickslabs.com\/go\/child-theme\">child theme<\/a>'s <code>functions.php<\/code> (w\/o the opening PHP tag) or a <a href=\"https:\/\/brickslabs.com\/go\/code-snippets-plugin\">code snippets plugin<\/a>:<\/p>\n  <\/div>\n  <div class=\"mepr-unauthorized-message\">\n    <p>This is a BricksLabs Pro tutorial.<\/p>\n<p>For full access login below or create your <a href=\"https:\/\/brickslabs.com\/pro\/\">BricksLabs Pro account<\/a><\/p>\n  <\/div>\n  <div class=\"mepr-login-form-wrap\">\n            \n<div class=\"mp_wrapper mp_login_form\">\n                  <!-- mp-login-form-start -->     <form name=\"mepr_loginform\" id=\"mepr_loginform\" class=\"mepr-form\" action=\"https:\/\/brickslabs.com\/login\/\" method=\"post\">\n            <div class=\"mp-form-row mepr_username\">\n        <div class=\"mp-form-label\">\n                              <label for=\"user_login\">Username<\/label>\n        <\/div>\n        <input type=\"text\" name=\"log\" id=\"user_login\" value=\"\" \/>\n      <\/div>\n      <div class=\"mp-form-row mepr_password\">\n        <div class=\"mp-form-label\">\n          <label for=\"user_pass\">Password<\/label>\n          <div class=\"mp-hide-pw\">\n            <input type=\"password\" name=\"pwd\" id=\"user_pass\" value=\"\" \/>\n            <button type=\"button\" class=\"button mp-hide-pw hide-if-no-js\" data-toggle=\"0\" aria-label=\"Show password\">\n              <span class=\"dashicons dashicons-visibility\" aria-hidden=\"true\"><\/span>\n            <\/button>\n          <\/div>\n        <\/div>\n      <\/div>\n            <div>\n        <label><input name=\"rememberme\" type=\"checkbox\" id=\"rememberme\" value=\"forever\" \/> Remember Me<\/label>\n      <\/div>\n      <div class=\"mp-spacer\">&nbsp;<\/div>\n      <div class=\"submit\">\n        <input type=\"submit\" name=\"wp-submit\" id=\"wp-submit\" class=\"button-primary mepr-share-button \" value=\"Log In\" \/>\n        <input type=\"hidden\" name=\"redirect_to\" value=\"\/wp-json\/wp\/v2\/posts\/7271\" \/>\n        <input type=\"hidden\" name=\"mepr_process_login_form\" value=\"true\" \/>\n        <input type=\"hidden\" name=\"mepr_is_login_page\" value=\"false\" \/>\n      <\/div>\n    <\/form>\n    <div class=\"mp-spacer\">&nbsp;<\/div>\n    <div class=\"mepr-login-actions\">\n        <a\n          href=\"https:\/\/brickslabs.com\/login\/?action=forgot_password\"\n          title=\"Click here to reset your password\"\n        >\n          Forgot Password        <\/a>\n    <\/div>\n\n      \n    <!-- mp-login-form-end --> \n  <\/div>\n      <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s say there&#8217;s a Events CPT with a &#8216;Event Year&#8217; custom taxonomy. Sample event year names could be: 2021, 2022, 2024, 2025, 2028 etc. We can set up a Terms query in <a  class=\"btl_autolink_hyperlink\"  href=\"https:\/\/brickslabs.com\/go\/bricks\"   >Bricks<\/a> to output these terms. Result: The reason 2021 is not present is because there are no posts that have been categorized with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7274,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[5,9],"tags":[222],"topic":[270],"class_list":["post-7271","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bricks","category-pro","tag-bricks-terms-query_vars","topic-filters"],"acf":[],"featured_image_src":"https:\/\/brickslabs.com\/wp-content\/uploads\/2024\/03\/terms-bricks-query-loop-586x400.png","featured_image_src_square":"https:\/\/brickslabs.com\/wp-content\/uploads\/2024\/03\/terms-bricks-query-loop-586x600.png","author_info":{"display_name":"Sridhar Katakam","author_link":"https:\/\/brickslabs.com\/author\/sridhar\/"},"_links":{"self":[{"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/posts\/7271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/comments?post=7271"}],"version-history":[{"count":0,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/posts\/7271\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/media\/7274"}],"wp:attachment":[{"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/media?parent=7271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/categories?post=7271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/tags?post=7271"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/brickslabs.com\/wp-json\/wp\/v2\/topic?post=7271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}