$value) {
$categories[] = $value['value'];
}
} else {
$categories = array();
}
if (isset($attributes['tags']) && ! empty($attributes['tags']) && is_array($attributes['tags'])) {
$tags = array();
$i = 1;
foreach ($attributes['tags'] as $key => $value) {
$tags[] = $value['value'];
}
} else {
$tags = array();
}
/* Setup the query */
$currentID = get_the_ID();
$query_args = array(
'posts_per_page' => $attributes['postsToShow'],
'post_status' => 'publish',
'order' => $attributes['order'],
'orderby' => $attributes['orderBy'],
'offset' => ($attributes['enablePagination'] == 'true') ? '' : $attributes['offset'],
'post_type' => $attributes['postType'],
'ignore_sticky_posts' => 1,
'paged' => $paged,
'post__not_in' => array($currentID)
);
if ('post' != $attributes['postType']) {
$tax_type = $attributes['taxType'];
if ($tax_type) {
if (!empty($categories)) {
$query_args['tax_query'][] = array(
'taxonomy' => (isset($tax_type)) ? $tax_type : 'category',
'field' => 'id',
'terms' => $categories,
'operator' => 'IN',
);
}
}
}
if ('post' == $attributes['postType']) {
$tax_type = $attributes['taxType'];
if ($tax_type) {
if (!empty($categories)) {
$query_args['tax_query'][] = array(
'taxonomy' => (isset($tax_type)) ? $tax_type : 'category',
'field' => 'id',
'terms' => $categories,
'operator' => 'IN',
);
} else {
$taxonomy = $tax_type; // this is the name of the taxonomy
$terms = get_terms($taxonomy);
if (!empty($terms)) {
$query_args['tax_query'][] = array(
'taxonomy' => (isset($tax_type)) ? $tax_type : 'category',
'field' => 'slug',
'terms' => wp_list_pluck($terms, 'slug')
);
}
}
}
}
if ($attributes['taxType'] == 'category') {
$query_args['category__in'] = $categories;
}
if ($attributes['taxType'] == 'post_tag') {
$query_args['tag__in'] = $tags;
}
/* Setup the query */
$grid_query = new WP_Query($query_args);
return $grid_query;
}
function blockspare_query_loop_and_wrapper($attributes, $blockclass = '', $design = '', $blockName = '', $paged = '', $layoutClass = false)
{
if ($attributes['enablePagination']) {
wp_enqueue_script('blockspare-pagination-js');
}
$unq_class = mt_rand(100000, 999999);
$blockuniqueclass = '';
if (!empty($attributes['uniqueClass'])) {
$blockuniqueclass = $attributes['uniqueClass'];
} else {
$blockuniqueclass = 'blockspare-posts-block-list-' . $unq_class;
}
$grid_query = blockspare_post_query($attributes);
if ($grid_query->have_posts()) {
$alignclass = blockspare_checkalignment($attributes['align']);
/* Build the block classes */
$class = "wp-block-blockspare-posts-block-blockspare-posts-block-latest-posts align" . $alignclass . " " . $attributes['blockHoverEffect'];
if (isset($attributes['className'])) {
$class .= ' ' . $attributes['className'];
}
if ($attributes['animation']) {
$class .= ' blockspare-block-animation';
}
$list_layout_class = $design;
$listgridClass = $blockclass . " ";
// if($blockName=='' ){
// $listgridClass .= "column-" . $attributes['columns'];
// }
/* Layout orientation class */
$grid_class = 'blockspare-posts-block-latest-post-wrap ' . $listgridClass . ' ' . $list_layout_class;
// if ($blockName != 'post-grid-masonry'){
// $grid_class .= ' ' . $blockuniqueclass;
// }else{
$class .= ' ' . $blockuniqueclass;
// }
$category_class = 'blockspare-posts-block-post-category';
if ($attributes['categoryLayoutOption'] == 'none') {
$category_class .= ' has-no-category-style';
}
$enableFeatureImage = true;
if (isset($attributes['enableFeatureImage'])) {
$enableFeatureImage = $attributes['enableFeatureImage'];
}
?>