Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

GetShopped (wp-ecommerce): how to filter certain categories? WordPress

  • SOLVED

In GetShopped (wp-ecommerce) there is a place on the page where all the categories are listed. I'd like to filter some of these out. Suggestions?

Answers (1)

2011-03-27

Sébastien | French WordpressDesigner answers:

You want filter the list of categories on the pages of the shop (in front end).

You can remove from the list a category or a group of category
add this code in functions.php

/*-----------------------------------------------------------------------------------*/
/* exclude a category or a group */
/*-----------------------------------------------------------------------------------*/

function my_exclude_categories($sql_segments) {
//$sql_segments[] = 'id != "13" '; //to exclude the cat 13
$sql_segments[] = "`group_id`='1'"; // to exclude the group 1
return $sql_segments;
}
add_filter(wpsc_display_category_loop_category_sql_segments,'my_exclude_categories');


Lawrence Krubner comments:

Sébastien,

Thanks, but this does not work for me. I already tried it.

I should have added more details to my question, but I wrote it when I was done working for the day and no longer thinking clearly.

I have 6 categories, and they have ids 1, 2, 3, 4, 5 and 6. And yet, if I do this, it has no effect:

function my_exclude_categories($sql_segments) {
//$sql_segments[] = 'id != "13" '; //to exclude the cat 13
$sql_segments[] = "`group_id`='3'"; // to exclude the group 1
return $sql_segments;
}
add_filter(wpsc_display_category_loop_category_sql_segments,'my_exclude_categories');


Strangely, only "5" has an effect. If I do this, then all the categories disappear:

function my_exclude_categories($sql_segments) {
//$sql_segments[] = 'id != "13" '; //to exclude the cat 13
$sql_segments[] = "`group_id`='5'"; // to exclude the group 1
return $sql_segments;
}
add_filter(wpsc_display_category_loop_category_sql_segments,'my_exclude_categories');


Possibly I'm confusing category and group?

I thought, as a workaround, I would go into the template itself, inside the loop that writes the HTML for each category, and possibly try to filter them out that way. But I could not find a way to find the category of an item, inside that loop.


Sébastien | French WordpressDesigner comments:

here you can create a group
http://your-domain.com/wp-admin/admin.php?page=wpsc-edit-groups

in a group you can have several categories.
You can remove from the list alll categories of the group 4 (for example) like this :




function my_exclude_categories($sql_segments) {
$sql_segments[] = "`group_id`='4'"; // to exclude the group 4
return $sql_segments;

}

add_filter(wpsc_display_category_loop_category_sql_segments,'my_exclude_categories');



if you want remove only the category 67
you can use this code :

function my_exclude_categories($sql_segments) {
//$sql_segments[] = 'id != "67" '; //to exclude the cat 67
return $sql_segments;
}
add_filter(wpsc_display_category_loop_category_sql_segments,'my_exclude_categories');





Sébastien | French WordpressDesigner comments:

soory : in the second code, i hae forget to remove this sign //

the code is useful like this
function my_exclude_categories($sql_segments) {
$sql_segments[] = 'id != "67" '; //to exclude the cat 67
return $sql_segments;
}
add_filter(wpsc_display_category_loop_category_sql_segments,'my_exclude_categories');