Show only specific category links in category page

Home / Forums / Virtue Theme / Show only specific category links in category page

This topic is: Resolved
[Resolved]
Posted in: Virtue Theme
October 21, 2022 at 4:56 am

Hi Want to show only specific phone category brand links on this page.

Still want products in unshown categories active on site, (they can be navigated to by search bar) or from google search, as can their child products.

page about phone brands

Is there a function I can add that will filter and display only specific categories spefified by ID.

Tried this code (id’s are the excluded product categories) but it messed with the product pages (that call the product category image and load it on the product page) see screen shot supplied.

/**
* Show products only of selected category.
*/
function get_subcategory_terms( $terms, $taxonomies, $args ) {

$new_terms = array();
$hide_category = array( 21443, 21444, 21445, 21446, 21448, 21449, 21450, 21451, 21452, 21453, 21454, 21455, 21456, 21457, 21458, 21459, 21460, 21461, 21462, 21463, 21464, 21466, 21467, 21468, 21471, 21472, 21473, 21474, 21475, 21476, 21477, 21478, 21479, 21480, 21481, 21483, 21484, 21485, 21486, 21487, 21489, 21490, 21492, 21495, 21496, 21497, 21498, 21499, 21500, 21501, 21502, 21503, 21504, 21505, 21507, 21508, 21509, 21510, 21511, 21512, 21513, 21514, 21515, 21516, 21517, 21518, 21519, 21520, 21521, 21522, 21524, 21525, 21526, 21527, 21528 ); // Ids of the category you don't want to display on the shop page

// if a product category and on the shop page
if ( in_array( 'product_cat', $taxonomies ) && !is_admin() ) {

foreach ( $terms as $key => $term ) {

if ( ! in_array( $term->term_id, $hide_category ) ) {
$new_terms[] = $term;
}
}
$terms = $new_terms;
}
return $terms;
}
add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );

NB: this shortcode will display the categories I want to link to… (so even to exclude the default include of categories would work)
[product_categories ids=”21447, 21465, 21469, 21470, 21482, 21488, 21491, 21493, 21494, 21506, 21523″]

*Cant hide it by css as it effects layout of products in category pages.

Thanks for your time . lee

  • This topic was modified 3 months, 2 weeks ago by lee.
  • This topic was modified 3 months, 2 weeks ago by lee.
  • This topic was modified 3 months, 2 weeks ago by lee.
  • You must be logged in to reply to this topic.