perch_shop_custom()

This add-on is deprecated. Please use the Perch Shop app.

Much like the default perch_content_custom() function, Shop has perch_shop_custom(). This function enables you to get a product listing customized by any of the available parameters.

Requires

Parameters

Type Description
Array Options array, see table below
Boolean Set to true to have the value returned instead of echoed.

Options array

Name Value
category A single category slug or array of category slugs to return content for. To exclude a category, prefix its name with an exclamation point.
template The name of a template to use to display the content.
sort The ID of the field to sort on.
sort-order Either ASC (ascending), DESC (descending) or RAND (random).
sort-type Either alpha or numeric. Default is alpha.
count The number of items to display.
start The item number to start displaying from.
filter The ID of a field to filter the results by.
match Used with filter, see the below table for values
value Used with filter and match. The value to match. For between and in, takes a comma delimited string. For regex takes PCRE regular expression.
category Filter by one or more categories. See Category filtering
category-match Either any or all. See Category filtering
skip-template True or false. Bypass template processing and return the content in an associative array.
return-html True or false. For use with skip-template. Adds the HTML onto the end of the returned array with key html.
split-items True or false. Return an array of individually templated items.
raw True or false. Returns unprocessed content, for use alongside skip-template.

Possible values for match

Value Aliases Description
eq is, exact equal to
neq not, !eq not equal to
gt greater than
gte greater than or equal to
lt less than
lte less than or equal to
contains the value exists within the content (a simple search)
!contains opposite of contains: the value does not exist within the content
regex regexp using a PCRE regular expression
between match between two values
!between opposite of between
eqbetween match between two values inclusively
!eqbetween opposite of eqbetween
in within match within a comma delimited content list (like a list of tags)
!in !within opposite of in

Usage examples

The below example filters on price, returning products equal to or between 10 and 20 units of currency, which are in the category ‘widgets’. I have also passed in a custom template for this listing.

<?php
    perch_shop_custom(array(
        'filter'=>'productPrice',
        'match'=>'eqbetween',
        'value'=>'10, 20',
        'category'=>'widgets',
        'template'=>'shop/special_listing.html'
    ));
?>

The perch_shop_custom function is very useful for displaying a customised list of products to given parameters.

The options for filter, match and value work just like perch_content_custom. Category can be either a single item or an array.