Hello @co50,
We highly recommend that you rename your function from cs_looper_custom_meta_query
to cs_looper_custom_yourpostype_meta_query
. For exmaple;
add_filter('cs_looper_custom_cardfront_meta_query', function ($result, $args) {
$item_cat_value = isset($_GET['item-cat']) ? $_GET['item-cat'] : '';
$query_args = array(
'post_type' => 'cardfronts',
'posts_per_page' => -1,
'orderby' => isset($_GET['orderby']) ? $_GET['orderby'] : 'title',
'order' => isset($_GET['order']) ? $_GET['order'] : 'asc',
);
if ($item_cat_value) {
$query_args['meta_query'] = array(
array(
'key' => 'item-cat',
'value' => $item_cat_value,
'compare' => 'IN',
)
);
}
$posts = get_posts($query_args);
return $posts;
}, 10, 2);
The above code will work with the card front custom post type. If you have another post type, you duplicate the code and modify the function name and the post type in the code like:
add_filter('cs_looper_custom_mycustomposttype_meta_query', function ($result, $args) {
$item_cat_value = isset($_GET['item-cat']) ? $_GET['item-cat'] : '';
$query_args = array(
'post_type' => 'mycustomposttype',
'posts_per_page' => -1,
'orderby' => isset($_GET['orderby']) ? $_GET['orderby'] : 'title',
'order' => isset($_GET['order']) ? $_GET['order'] : 'asc',
);
if ($item_cat_value) {
$query_args['meta_query'] = array(
array(
'key' => 'item-cat',
'value' => $item_cat_value,
'compare' => 'IN',
)
);
}
$posts = get_posts($query_args);
return $posts;
}, 10, 2);
Hope this helps.