Warning: include_once(/home4/aquapan/public_html/cjbarnaby/wp-content/plugins/wp-super-cache/wp-cache-phase1.php): failed to open stream: No such file or directory in /home/revela25/public_html/cjbarnaby/wp-content/advanced-cache.php on line 22

Warning: include_once(): Failed opening '/home4/aquapan/public_html/cjbarnaby/wp-content/plugins/wp-super-cache/wp-cache-phase1.php' for inclusion (include_path='.:/opt/cpanel/ea-php74/root/usr/share/pear') in /home/revela25/public_html/cjbarnaby/wp-content/advanced-cache.php on line 22

Warning: include(/home4/aquapan/public_html/cjbarnaby/wp-content/plugins/wp-super-cache/wp-cache-base.php): failed to open stream: No such file or directory in /home/revela25/public_html/cjbarnaby/wp-content/plugins/wp-super-cache/wp-cache.php on line 137

Warning: include(): Failed opening '/home4/aquapan/public_html/cjbarnaby/wp-content/plugins/wp-super-cache/wp-cache-base.php' for inclusion (include_path='.:/opt/cpanel/ea-php74/root/usr/share/pear') in /home/revela25/public_html/cjbarnaby/wp-content/plugins/wp-super-cache/wp-cache.php on line 137

Warning: include_once(/home4/aquapan/public_html/cjbarnaby/wp-content/plugins/wp-super-cache/ossdl-cdn.php): failed to open stream: No such file or directory in /home/revela25/public_html/cjbarnaby/wp-content/plugins/wp-super-cache/wp-cache.php on line 174

Warning: include_once(): Failed opening '/home4/aquapan/public_html/cjbarnaby/wp-content/plugins/wp-super-cache/ossdl-cdn.php' for inclusion (include_path='.:/opt/cpanel/ea-php74/root/usr/share/pear') in /home/revela25/public_html/cjbarnaby/wp-content/plugins/wp-super-cache/wp-cache.php on line 174

Warning: Cannot modify header information - headers already sent by (output started at /home/revela25/public_html/cjbarnaby/wp-content/advanced-cache.php:22) in /home/revela25/public_html/cjbarnaby/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/revela25/public_html/cjbarnaby/wp-content/advanced-cache.php:22) in /home/revela25/public_html/cjbarnaby/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/revela25/public_html/cjbarnaby/wp-content/advanced-cache.php:22) in /home/revela25/public_html/cjbarnaby/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/revela25/public_html/cjbarnaby/wp-content/advanced-cache.php:22) in /home/revela25/public_html/cjbarnaby/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/revela25/public_html/cjbarnaby/wp-content/advanced-cache.php:22) in /home/revela25/public_html/cjbarnaby/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/revela25/public_html/cjbarnaby/wp-content/advanced-cache.php:22) in /home/revela25/public_html/cjbarnaby/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/revela25/public_html/cjbarnaby/wp-content/advanced-cache.php:22) in /home/revela25/public_html/cjbarnaby/wp-includes/rest-api/class-wp-rest-server.php on line 1893

Warning: Cannot modify header information - headers already sent by (output started at /home/revela25/public_html/cjbarnaby/wp-content/advanced-cache.php:22) in /home/revela25/public_html/cjbarnaby/wp-includes/rest-api/class-wp-rest-server.php on line 1893
{"id":3975,"date":"2023-03-06T22:56:30","date_gmt":"2023-03-06T22:56:30","guid":{"rendered":"http:\/\/cjbarnaby.com\/?p=3975"},"modified":"2023-03-06T22:57:48","modified_gmt":"2023-03-06T22:57:48","slug":"woocommerce-products-listing-page-exclude-category-filter","status":"publish","type":"post","link":"http:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/","title":{"rendered":"Woocommerce Products Listing Page Exclude Category Filter"},"content":{"rendered":"\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t

I work in WordPress and Woocommerce often and this code was generated by asking the right questions for ChatGPT which is a very helpful AI.<\/p>

It resides in your functions.php for your activated theme to apply to your product listings page in Woocommerce.<\/p>

I needed something that would help me to pick out certain product items with a bit more granularity and this helped immensely.<\/p>

Add it to your site at your own risk. I’m recording it here for my own use specifically however if you get use from it then that’s all good by me. <\/p>

\u00a0<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\n\t\t\t\t\t\/\/ woocommerce exclude category filter on all products listing page\n\n\/\/ Add filter option to exclude products from category\nadd_action( 'restrict_manage_posts', 'add_exclude_category_filter' );\nfunction add_exclude_category_filter() {\n    $current_cat = isset( $_GET['product_cat'] ) ? $_GET['product_cat'] : '';\n    $exclude_cat = isset( $_GET['exclude_category'] ) ? $_GET['exclude_category'] : '';\n    ?>\n    <select name=\"exclude_category\">\n        <option value=\"\"><?php _e( 'Exclude category', 'woocommerce' ); ?><\/option>\n        <?php\n        $categories = get_terms( 'product_cat', array(\n            'hide_empty' => true,\n        ) );\n        foreach ( $categories as $category ) :\n            $selected = $category->term_id == $exclude_cat ? 'selected=\"selected\"' : '';\n            $current = $category->term_id == $current_cat ? 'current-cat' : '';\n            ?>\n            <option class=\"<?php echo esc_attr( $current ); ?>\" value=\"<?php echo esc_attr( $category->term_id ); ?>\" <?php echo $selected; ?>>\n                <?php echo esc_html( $category->name ); ?>\n            <\/option>\n        <?php endforeach; ?>\n    <\/select>\n    <?php\n}\n\nfunction custom_product_query( $query ) {\n\n    \/\/ Check if we're on the products listing page\n    if ( $query->is_admin && $query->query['post_type'] === 'product' && ! is_null( $query->query_vars['s'] ) ) {\n\n        \/\/ Check if the exclude category filter is set\n        if ( isset( $_GET['exclude_category'] ) && ! empty( $_GET['exclude_category'] ) ) {\n            $exclude_category = absint( $_GET['exclude_category'] );\n            $tax_query = array(\n                array(\n                    'taxonomy' => 'product_cat',\n                    'field'    => 'term_id',\n                    'terms'    => $exclude_category,\n                    'operator' => 'NOT IN',\n                ),\n            );\n            $query->set( 'tax_query', $tax_query );\n        }\n    }\n}\nadd_action( 'pre_get_posts', 'custom_product_query' );\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\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>I work in WordPress and Woocommerce often and this code was generated by asking the right questions for ChatGPT which is a very helpful AI. It resides in your functions.php for your activated theme to apply to your product listings page in Woocommerce. I needed something that would help me to pick out certain product [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3137],"tags":[],"class_list":["post-3975","post","type-post","status-publish","format-standard","hentry","category-woocommerce"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Woocommerce Products Listing Page Exclude Category Filter - cjbarnaby<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Woocommerce Products Listing Page Exclude Category Filter - cjbarnaby\" \/>\n<meta property=\"og:description\" content=\"I work in WordPress and Woocommerce often and this code was generated by asking the right questions for ChatGPT which is a very helpful AI. It resides in your functions.php for your activated theme to apply to your product listings page in Woocommerce. I needed something that would help me to pick out certain product [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/\" \/>\n<meta property=\"og:site_name\" content=\"cjbarnaby\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-06T22:56:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-06T22:57:48+00:00\" \/>\n<meta name=\"author\" content=\"cjbarnaby\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cjbarnaby\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/\",\"url\":\"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/\",\"name\":\"Woocommerce Products Listing Page Exclude Category Filter - cjbarnaby\",\"isPartOf\":{\"@id\":\"http:\/\/cjbarnaby.com\/#website\"},\"datePublished\":\"2023-03-06T22:56:30+00:00\",\"dateModified\":\"2023-03-06T22:57:48+00:00\",\"author\":{\"@id\":\"http:\/\/cjbarnaby.com\/#\/schema\/person\/c480873ae8f074e8a2ba01f1e7c020f7\"},\"breadcrumb\":{\"@id\":\"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/cjbarnaby.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Woocommerce Products Listing Page Exclude Category Filter\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/cjbarnaby.com\/#website\",\"url\":\"http:\/\/cjbarnaby.com\/\",\"name\":\"cjbarnaby\",\"description\":\"life attachments = temporal meaning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/cjbarnaby.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/cjbarnaby.com\/#\/schema\/person\/c480873ae8f074e8a2ba01f1e7c020f7\",\"name\":\"cjbarnaby\",\"url\":\"http:\/\/cjbarnaby.com\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Woocommerce Products Listing Page Exclude Category Filter - cjbarnaby","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/","og_locale":"en_US","og_type":"article","og_title":"Woocommerce Products Listing Page Exclude Category Filter - cjbarnaby","og_description":"I work in WordPress and Woocommerce often and this code was generated by asking the right questions for ChatGPT which is a very helpful AI. It resides in your functions.php for your activated theme to apply to your product listings page in Woocommerce. I needed something that would help me to pick out certain product [&hellip;]","og_url":"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/","og_site_name":"cjbarnaby","article_published_time":"2023-03-06T22:56:30+00:00","article_modified_time":"2023-03-06T22:57:48+00:00","author":"cjbarnaby","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cjbarnaby","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/","url":"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/","name":"Woocommerce Products Listing Page Exclude Category Filter - cjbarnaby","isPartOf":{"@id":"http:\/\/cjbarnaby.com\/#website"},"datePublished":"2023-03-06T22:56:30+00:00","dateModified":"2023-03-06T22:57:48+00:00","author":{"@id":"http:\/\/cjbarnaby.com\/#\/schema\/person\/c480873ae8f074e8a2ba01f1e7c020f7"},"breadcrumb":{"@id":"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cjbarnaby.com\/woocommerce-products-listing-page-exclude-category-filter\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/cjbarnaby.com\/"},{"@type":"ListItem","position":2,"name":"Woocommerce Products Listing Page Exclude Category Filter"}]},{"@type":"WebSite","@id":"http:\/\/cjbarnaby.com\/#website","url":"http:\/\/cjbarnaby.com\/","name":"cjbarnaby","description":"life attachments = temporal meaning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/cjbarnaby.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/cjbarnaby.com\/#\/schema\/person\/c480873ae8f074e8a2ba01f1e7c020f7","name":"cjbarnaby","url":"http:\/\/cjbarnaby.com\/author\/admin\/"}]}},"_links":{"self":[{"href":"http:\/\/cjbarnaby.com\/wp-json\/wp\/v2\/posts\/3975","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/cjbarnaby.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cjbarnaby.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cjbarnaby.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cjbarnaby.com\/wp-json\/wp\/v2\/comments?post=3975"}],"version-history":[{"count":8,"href":"http:\/\/cjbarnaby.com\/wp-json\/wp\/v2\/posts\/3975\/revisions"}],"predecessor-version":[{"id":3983,"href":"http:\/\/cjbarnaby.com\/wp-json\/wp\/v2\/posts\/3975\/revisions\/3983"}],"wp:attachment":[{"href":"http:\/\/cjbarnaby.com\/wp-json\/wp\/v2\/media?parent=3975"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cjbarnaby.com\/wp-json\/wp\/v2\/categories?post=3975"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cjbarnaby.com\/wp-json\/wp\/v2\/tags?post=3975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}