You can display posts/custom post types associated with a certain custom field using the following attributes.
- meta_key – Custom field key.
- meta_value – Custom field value.
- meta_value_num – Custom field value number
- meta_compare – Operator to test the meta_value. Possible values are ‘=’, ‘!=’, ‘>’, ‘>=’, ‘<‘, ‘<=’, ‘LIKE’, ‘NOT LIKE’, ‘IN’, ‘NOT IN’, ‘BETWEEN’, ‘NOT BETWEEN’, ‘NOT EXISTS’, ‘REGEXP’, ‘NOT REGEXP’ or ‘RLIKE’. Default value is ‘=’.
Examples:
[wcp-carousel id="767" meta_key="color"]
Above shortcode will display posts where the custom field key is color, regardless of the custom field value.
[wcp-carousel id="767" meta_value="blue"]
Above shortcode will display posts where the custom field value is blue, regardless of the custom field key.
[wcp-carousel id="767" meta_value="blue" meta_key="color" meta_compare="!="]
Above shortcode will display posts where the custom field key is color and the custom field value IS NOT blue.
[wcp-carousel id="767" meta_key="price" meta_value="22" meta_compare="<=" post_type="product"]
Above shortcode will display Products where the custom field key is price and the custom field value that is LESS THAN OR EQUAL TO 22.
By using the ‘meta_value’ parameter the value 99 will be considered greater than 100 as the data are stored as ‘strings’, not ‘numbers’. For number comparison use ‘meta_value_num’.