$limit && $limit != '-1' ) { $posts_per_page = $limit; } $args['posts_per_page'] = $posts_per_page; $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $offset = $posts_per_page * ( (int) $paged - 1 ); $args['paged'] = $paged; if ( intval( $args['posts_per_page'] ) > $limit - $offset && $limit != '-1' ) { $args['posts_per_page'] = $limit - $offset; } } $adv_filter = ( isset( $_REQUEST['post_filter'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['post_filter'] ) ) : [] ); $taxFilter = ( ! empty( $_REQUEST['tgp_filter_taxonomy'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tgp_filter_taxonomy'] ) ) : null ); $taxHierarchical = ! empty( $_REQUEST['tgp_filter_taxonomy_hierarchical'] ); $taxFilterTerms = []; $taxFilterOperator = 'IN'; $taxQ = []; if ( in_array( 'tpg_taxonomy', $adv_filter ) && isset( $_REQUEST['tpg_taxonomy'] ) ) { $tpgTaxonomy = array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['tpg_taxonomy'] ) ); if ( is_array( $tpgTaxonomy ) && ! empty( $tpgTaxonomy ) ) { foreach ( $tpgTaxonomy as $taxonomy ) { $terms = ( isset( $_REQUEST[ 'term_' . $taxonomy ] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST[ 'term_' . $taxonomy ] ) ) : [] ); if ( $taxonomy == $taxFilter ) { $taxFilterTerms = $terms; } if ( is_array( $terms ) && ! empty( $terms ) ) { $operator = ( isset( $_REQUEST[ 'term_operator_' . $taxonomy ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ 'term_operator_' . $taxonomy ] ) ) : 'IN' ); $taxQ[] = [ 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $terms, 'operator' => $operator, ]; } } } if ( count( $taxQ ) >= 2 ) { $relation = ( isset( $_REQUEST['taxonomy_relation'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['taxonomy_relation'] ) ) : 'AND' ); $taxQ['relation'] = $relation; } } if ( ! empty( $taxQ ) ) { $args['tax_query'] = $taxQ; } if ( in_array( 'order', $adv_filter ) ) { $order_by = ( isset( $_REQUEST['order_by'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['order_by'] ) ) : null ); $order = ( isset( $_REQUEST['order'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['order'] ) ) : null ); if ( $order ) { $args['order'] = $order; } if ( $order_by ) { $args['orderby'] = $order_by; $meta_key = ! empty( $_REQUEST['tpg_meta_key'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_meta_key'] ) ) : null; if ( in_array( $order_by, array_keys( Options::rtMetaKeyType() ), true ) && $meta_key ) { $args['orderby'] = $order_by; $args['meta_key'] = $meta_key; } } } if ( isset( $_REQUEST['orderby'] ) ) { $orderby = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ); switch ( $orderby ) { case 'menu_order': $args['orderby'] = 'menu_order title'; $args['order'] = 'ASC'; break; case 'date': $args['orderby'] = 'date'; $args['order'] = 'DESC'; break; case 'price': $args['orderby'] = 'meta_value_num'; $args['meta_key'] = '_price'; $args['order'] = 'ASC'; break; case 'price-desc': $args['orderby'] = 'meta_value_num'; $args['meta_key'] = '_price'; $args['order'] = 'DESC'; break; case 'rating': // Sorting handled later though a hook. add_filter( 'posts_clauses', [ $this, 'order_by_rating_post_clauses' ] ); break; case 'title': $args['orderby'] = 'title'; $args['order'] = 'ASC'; break; } } if ( in_array( 'tpg_post_status', $adv_filter ) ) { $post_status = ( isset( $_REQUEST['tpg_post_status'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['tpg_post_status'] ) ) : [] ); if ( ! empty( $post_status ) ) { $args['post_status'] = $post_status; } } else { $args['post_status'] = 'publish'; } $filterAuthors = []; $author = ( isset( $_REQUEST['author'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['author'] ) ) : [] ); if ( in_array( 'author', $adv_filter ) && ! empty( $author ) ) { $filterAuthors = $args['author__in'] = $author; } $s = ( isset( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : [] ); if ( in_array( 's', $adv_filter ) && ! empty( $s ) ) { $args['s'] = $s; } if ( in_array( 'date_range', $adv_filter ) ) { $startDate = ( ! empty( $_REQUEST['date_range_start'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['date_range_start'] ) ) : null ); $endDate = ( ! empty( $_REQUEST['date_range_end'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['date_range_end'] ) ) : null ); if ( $startDate && $endDate ) { $args['date_query'] = [ [ 'after' => $startDate, 'before' => $endDate, 'inclusive' => true, ], ]; } } $settings = get_option( rtTPG()->options['settings'] ); $override_items = ! empty( $settings['template_override_items'] ) ? $settings['template_override_items'] : []; $dataArchive = null; if ( ( is_archive() || is_search() || is_tag() || is_author() ) && ! empty( $override_items ) ) { unset( $args['post_type'] ); unset( $args['tax_query'] ); unset( $args['author__in'] ); $obj = get_queried_object(); $aType = $aValue = null; if ( in_array( 'tag-archive', $override_items ) && is_tag() ) { if ( ! empty( $obj->slug ) ) { $aValue = $args['tag'] = $obj->slug; $aType = 'tag'; } } elseif ( in_array( 'category-archive', $override_items ) && is_category() ) { if ( ! empty( $obj->slug ) ) { $aValue = $args['category_name'] = $obj->slug; } $aType = 'category'; } elseif ( in_array( 'author-archive', $override_items ) && is_author() ) { $aValue = $args['author'] = $obj->ID; $aType = 'author'; } elseif ( in_array( 'search', $override_items ) && is_search() ) { $aValue = $args['s'] = get_search_query(); $aType = 'search'; } $dataArchive = " data-archive='{$aType}' data-archive-value='{$aValue}'"; $args['posts_per_archive_page'] = $args['posts_per_page']; } $containerDataAttr = null; $containerDataAttr .= " data-layout='{$layout}' data-desktop-col='{$dCol}' data-tab-col='{$tCol}' data-mobile-col='{$mCol}'"; $dCol = 5 === $dCol ? '24' : round( 12 / $dCol ); $tCol = 5 === $dCol ? '24' : round( 12 / $tCol ); $mCol = 5 === $dCol ? '24' : round( 12 / $mCol ); if ( $isCarousel ) { $dCol = $tCol = $mCol = 12; } $arg['grid'] = "rt-col-md-{$dCol} rt-col-sm-{$tCol} rt-col-xs-{$mCol}"; if ( ( 'layout2' === $layout ) || ( 'layout3' === $layout ) ) { $iCol = ( isset( $_REQUEST['tgp_layout2_image_column'] ) ? absint( $_REQUEST['tgp_layout2_image_column'] ) : 4 ); $iCol = $iCol > 12 ? 4 : $iCol; $cCol = 12 - $iCol; $arg['image_area'] = "rt-col-sm-{$iCol} rt-col-xs-12 "; $arg['content_area'] = "rt-col-sm-{$cCol} rt-col-xs-12 "; } if ( 'layout4' === $layout ) { $arg['image_area'] = 'rt-col-lg-6 rt-col-md-6 rt-col-sm-12 rt-col-xs-12 '; $arg['content_area'] = 'rt-col-lg-6 rt-col-md-6 rt-col-sm-12 rt-col-xs-12 '; } $gridType = ! empty( $_REQUEST['grid_style'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['grid_style'] ) ) : 'even'; $arg_class = []; $arg_class[] = ' rt-grid-item'; if ( ! $isCarousel && ! $isOffset ) { $arg_class[] = $gridType . '-grid-item'; } if ( $isOffset ) { $arg_class[] = 'rt-offset-item'; } $catHaveBg = ( isset( $_REQUEST['tpg_category_bg'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_category_bg'] ) ) : '' ); if ( ! empty( $catHaveBg ) ) { $arg_class[] = 'category-have-bg'; } $imgAnimationType = isset( $_REQUEST['tpg_image_animation'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_image_animation'] ) ) : ''; if ( ! empty( $imgAnimationType ) ) { $arg_class[] = $imgAnimationType; } $masonryG = null; if ( 'even' === $gridType && ! $isIsotope && ! $isCarousel ) { $masonryG = 'tpg-even'; } elseif ( 'masonry' === $gridType && ! $isIsotope && ! $isCarousel ) { $masonryG = ' tpg-masonry'; } $preLoader = $preLoaderHtml = null; if ( $isIsotope ) { $arg_class[] = 'isotope-item'; $preLoader = 'tpg-pre-loader'; } if ( $isCarousel ) { $arg_class[] = 'swiper-slide'; $preLoader = 'tpg-pre-loader'; } $arg['class'] = implode( ' ', $arg_class ); if ( $preLoader ) { $preLoaderHtml = '
'; } $margin = ! empty( $_REQUEST['margin_option'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['margin_option'] ) ) : 'default'; if ( 'no' === $margin ) { $arg_class[] = 'no-margin'; } if ( ! empty( $_REQUEST['tpg_image_type'] ) && 'circle' === $_REQUEST['tpg_image_type'] ) { $arg_class[] = 'tpg-img-circle'; } $arg['anchorClass'] = null; $arg['anchorClass'] = $arg['link_target'] = null; $link = isset( $_REQUEST['link_to_detail_page'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['link_to_detail_page'] ) ) : '1'; $link = ( 'yes' === $link ) ? '1' : $link; $isSinglePopUp = false; $linkType = ! empty( $_REQUEST['detail_page_link_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['detail_page_link_type'] ) ) : 'popup'; if ( '1' === $link ) { if ( 'popup' === $linkType && rtTPG()->hasPro() ) { $popupType = ! empty( $_REQUEST['popup_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['popup_type'] ) ) : 'single'; if ( 'single' === $popupType ) { $arg['anchorClass'] .= ' tpg-single-popup'; $isSinglePopUp = true; } else { $arg['anchorClass'] .= ' tpg-multi-popup'; } } else { $arg['link_target'] = ! empty( $_REQUEST['link_target'] ) ? ' target="' . sanitize_text_field( wp_unslash( $_REQUEST['link_target'] ) ) . '"' : null; } } else { $arg['anchorClass'] = ' disabled'; } $isSinglePopUp = false; $linkType = ! empty( $_REQUEST['detail_page_link_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['detail_page_link_type'] ) ) : 'popup'; if ( '1' === $link && 'popup' === $linkType && rtTPG()->hasPro() ) { $popupType = ! empty( $_REQUEST['popup_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['popup_type'] ) ) : 'single'; if ( 'single' === $popupType ) { $arg['anchorClass'] .= ' tpg-single-popup'; $isSinglePopUp = true; } else { $arg['anchorClass'] .= ' tpg-multi-popup'; } } $parentClass = ( ! empty( $_REQUEST['parent_class'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['parent_class'] ) ) : null ); $defaultImgId = ( ! empty( $_REQUEST['default_preview_image'] ) ? absint( $_REQUEST['default_preview_image'] ) : null ); $customImgSize = ( ! empty( $_REQUEST['custom_image_size'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['custom_image_size'] ) ) : [] ); $fSmallImgSize = ( isset( $_REQUEST['featured_small_image_size'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['featured_small_image_size'] ) ) : 'medium' ); $customSmallImgSize = ( ! empty( $_REQUEST['custom_small_image_size'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['custom_small_image_size'] ) ) : [] ); $arg['items'] = isset( $_REQUEST['item_fields'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['item_fields'] ) ) : []; $arg['scID'] = $scID = isset( $_REQUEST['sc_id'] ) ? absint( $_REQUEST['sc_id'] ) : null; if ( isset( $arg['excerpt_type'] ) && 'full' === $arg['excerpt_type'] && ( $key = array_search( 'read_more', $arg['items'] ) ) !== false ) { unset( $arg['items'][ $key ] ); } if ( isset( $_REQUEST['ignore_sticky_posts'] ) ) { $args['ignore_sticky_posts'] = isset( $_REQUEST['ignore_sticky_posts'] ); } $filters = ! empty( $_REQUEST['tgp_filter'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['tgp_filter'] ) ) : []; $action_term = ! empty( $_REQUEST['tgp_default_filter'] ) ? absint( $_REQUEST['tgp_default_filter'] ) : 0; $hide_all_button = ! empty( $_REQUEST['tpg_hide_all_button'] ) ? true : false; if ( $taxHierarchical ) { $terms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, 0 ); } else { $terms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true ); } if ( $hide_all_button && ! $action_term ) { if ( ! empty( $terms ) ) { $allKeys = array_keys( $terms ); $action_term = $allKeys[0]; } } if ( in_array( '_taxonomy_filter', $filters ) && $taxFilter && $action_term ) { $args['tax_query'] = [ [ 'taxonomy' => $taxFilter, 'field' => 'term_id', 'terms' => [ $action_term ], ], ]; } if ( $limit != - 1 && $pagination ) { $tempArgs = $args; $tempArgs['posts_per_page'] = $limit; $tempArgs['paged'] = 1; $tempArgs['fields'] = 'ids'; $tempQ = new \WP_Query( $tempArgs ); if ( ! empty( $tempQ->posts ) ) { $args['post__in'] = $tempQ->posts; } } if ( $pagination && $queryOffset && isset( $args['paged'] ) ) { $queryOffset = ( $posts_per_page * ( $args['paged'] - 1 ) ) + $queryOffset; } if ( $queryOffset ) { $args['offset'] = $queryOffset; } $arg['title_tag'] = ( ! empty( $_REQUEST['title_tag'] ) && in_array( $_REQUEST['title_tag'], array_keys( Options::getTitleTags() ) ) ) ? sanitize_text_field( wp_unslash( $_REQUEST['title_tag'] ) ) : 'h3'; $gridQuery = new \WP_Query( $args ); $styleMeta = [ 'primary_color' => isset( $_REQUEST['primary_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['primary_color'] ) ) : null, 'button_bg_color' => isset( $_REQUEST['button_bg_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_bg_color'] ) ) : null, 'button_active_bg_color' => isset( $_REQUEST['button_active_bg_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_active_bg_color'] ) ) : null, 'button_hover_bg_color' => isset( $_REQUEST['button_hover_bg_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_hover_bg_color'] ) ) : null, 'button_text_color' => isset( $_REQUEST['button_text_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_text_color'] ) ) : null, 'button_text_bg_color' => isset( $_REQUEST['button_text_bg_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_text_bg_color'] ) ) : null, 'button_border_color' => isset( $_REQUEST['button_border_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_border_color'] ) ) : null, 'button_hover_text_color' => isset( $_REQUEST['button_hover_text_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['button_hover_text_color'] ) ) : null, 'overlay_color' => isset( $_REQUEST['overlay_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['overlay_color'] ) ) : null, 'overlay_opacity' => isset( $_REQUEST['overlay_opacity'] ) ? absint( $_REQUEST['overlay_opacity'] ) : null, 'overlay_padding' => isset( $_REQUEST['overlay_padding'] ) ? absint( $_REQUEST['overlay_padding'] ) : null, 'tgp_gutter' => isset( $_REQUEST['tgp_gutter'] ) ? absint( $_REQUEST['tgp_gutter'] ) : null, 'tpg_read_more_button_border_radius' => isset( $_REQUEST['tpg_read_more_button_border_radius'] ) ? absint( $_REQUEST['tpg_read_more_button_border_radius'] ) : null, 'tpg_full_area_bg' => isset( $_REQUEST['tpg_full_area_bg'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_full_area_bg'] ) ) : null, 'tpg_full_area_margin' => isset( $_REQUEST['tpg_full_area_margin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_full_area_margin'] ) ) : null, 'tpg_full_area_padding' => isset( $_REQUEST['tpg_full_area_margin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_full_area_margin'] ) ) : null, 'tpg_content_wrap_bg' => isset( $_REQUEST['tpg_content_wrap_bg'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_content_wrap_bg'] ) ) : null, 'tpg_content_wrap_border' => isset( $_REQUEST['tpg_content_wrap_border'] ) ? absint( $_REQUEST['tpg_content_wrap_border'] ) : null, 'tpg_content_wrap_border_color' => isset( $_REQUEST['tpg_content_wrap_border_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_content_wrap_border_color'] ) ) : null, 'tpg_content_wrap_border_radius' => isset( $_REQUEST['tpg_content_wrap_border_radius'] ) ? absint( $_REQUEST['tpg_content_wrap_border_radius'] ) : null, 'tpg_content_wrap_shadow' => isset( $_REQUEST['tpg_content_wrap_shadow'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_content_wrap_shadow'] ) ) : null, 'tpg_box_padding' => isset( $_REQUEST['tpg_box_padding'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_box_padding'] ) ) : null, 'tpg_content_padding' => isset( $_REQUEST['tpg_content_padding'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_content_padding'] ) ) : null, 'tpg_heading_bg' => isset( $_REQUEST['tpg_heading_bg'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_heading_bg'] ) ) : null, 'tpg_heading_color' => isset( $_REQUEST['tpg_heading_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_heading_color'] ) ) : null, 'tpg_heading_border_color' => isset( $_REQUEST['tpg_heading_border_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_heading_border_color'] ) ) : null, 'tpg_heading_border_size' => isset( $_REQUEST['tpg_heading_border_size'] ) ? absint( $_REQUEST['tpg_heading_border_size'] ) : null, 'tpg_heading_margin' => isset( $_REQUEST['tpg_heading_margin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_margin'] ) ) : null, 'tpg_heading_padding' => isset( $_REQUEST['tpg_heading_padding'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_padding'] ) ) : null, 'tpg_category_bg' => isset( $_REQUEST['tpg_category_bg'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_category_bg'] ) ) : null, 'tpg_category_color' => isset( $_REQUEST['tpg_category_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['tpg_category_color'] ) ) : null, 'tpg_category_border_radius' => isset( $_REQUEST['tpg_category_border_radius'] ) ? absint( $_REQUEST['tpg_category_border_radius'] ) : null, 'tpg_category_margin' => isset( $_REQUEST['tpg_category_margin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_category_margin'] ) ) : null, 'tpg_category_padding' => isset( $_REQUEST['tpg_category_padding'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_category_padding'] ) ) : null, 'rt_tpg_category_font_size' => isset( $_REQUEST['rt_tpg_category_font_size'] ) ? absint( $_REQUEST['rt_tpg_category_font_size'] ) : null, 'tpg_image_border_radius' => isset( $_REQUEST['tpg_image_border_radius'] ) ? absint( $_REQUEST['tpg_image_border_radius'] ) : null, 'title_color' => isset( $_REQUEST['title_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['title_color'] ) ) : null, 'title_size' => isset( $_REQUEST['title_size'] ) ? absint( $_REQUEST['title_size'] ) : null, 'title_weight' => isset( $_REQUEST['title_weight'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['title_weight'] ) ) : null, 'title_alignment' => isset( $_REQUEST['title_alignment'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['title_alignment'] ) ) : null, 'title_hover_color' => isset( $_REQUEST['title_hover_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['title_hover_color'] ) ) : null, 'excerpt_color' => isset( $_REQUEST['excerpt_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['excerpt_color'] ) ) : null, 'excerpt_size' => isset( $_REQUEST['excerpt_size'] ) ? absint( $_REQUEST['excerpt_size'] ) : null, 'excerpt_weight' => isset( $_REQUEST['excerpt_weight'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['excerpt_weight'] ) ) : null, 'excerpt_alignment' => isset( $_REQUEST['excerpt_alignment'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['excerpt_alignment'] ) ) : null, 'meta_data_color' => isset( $_REQUEST['meta_data_color'] ) ? sanitize_hex_color( wp_unslash( $_REQUEST['meta_data_color'] ) ) : null, 'meta_data_size' => isset( $_REQUEST['meta_data_size'] ) ? absint( $_REQUEST['meta_data_size'] ) : null, 'meta_data_weight' => isset( $_REQUEST['meta_data_weight'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['meta_data_weight'] ) ) : null, 'meta_data_alignment' => isset( $_REQUEST['meta_data_alignment'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['meta_data_alignment'] ) ) : null, ]; $data .= Fns::layoutStyle( $layoutID, $styleMeta, $layout ); $containerDataAttr .= ''; $data .= "
"; // widget heading. $heading_tag = isset( $_REQUEST['tpg_heading_tag'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_tag'] ) ) : 'h2'; $heading_style = isset( $_REQUEST['tpg_heading_style'] ) && ! empty( $_REQUEST['tpg_heading_style'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_style'] ) ) : 'style1'; $heading_alignment = isset( $_REQUEST['tpg_heading_alignment'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_alignment'] ) ) : ''; $heading_link = isset( $_REQUEST['tpg_heading_link'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_heading_link'] ) ) : ''; if ( ! empty( $arg['items'] ) && in_array( 'heading', $arg['items'] ) ) { $data .= sprintf( '
', $heading_style, $heading_alignment ); $data .= ''; if ( $heading_link ) { $data .= sprintf( '<%1$s class="tpg-widget-heading">%3$s', $heading_tag, $heading_link, get_the_title( $scID ) ); } else { $data .= sprintf( '<%1$s class="tpg-widget-heading">%2$s', $heading_tag, get_the_title( $scID ) ); } $data .= ''; $data .= '
'; } $filters = ! empty( $_REQUEST['tgp_filter'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['tgp_filter'] ) ) : []; if ( ! empty( $filters ) && ( $isGrid || $isOffset || $isWooCom ) ) { $data .= "
"; $allText = apply_filters( 'tpg_filter_all_text', esc_html__( 'All', 'the-post-grid' ), $_REQUEST ); $selectedSubTermsForButton = null; if ( in_array( '_taxonomy_filter', $filters ) && $taxFilter ) { $filterType = ( ! empty( $_REQUEST['tgp_filter_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tgp_filter_type'] ) ) : null ); $post_count = ( ! empty( $_REQUEST['tpg_post_count'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_post_count'] ) ) : null ); $postCountClass = ( $post_count ? ' has-post-count' : null ); $allSelect = ' selected'; $isTermSelected = false; if ( $action_term && $taxFilter ) { $isTermSelected = true; $allSelect = null; } if ( ! $filterType || 'dropdown' === $filterType ) { $data .= "
"; $termDefaultText = $allText; $dataTerm = 'all'; $htmlButton = ''; $selectedSubTerms = null; $pCount = 0; if ( ! empty( $terms ) ) { $i = 0; foreach ( $terms as $id => $term ) { $pCount = $pCount + $term['count']; $sT = null; if ( $taxHierarchical ) { $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id ); if ( ! empty( $subTerms ) ) { $count = 0; $item = $allCount = null; foreach ( $subTerms as $stId => $t ) { $count = $count + absint( $t['count'] ); $sTPostCount = ( $post_count ? " ({$t['count']})" : null ); $item .= "{$t['name']}{$sTPostCount}"; } if ( $post_count ) { $allCount = " ({$count})"; } $sT .= "'; } if ( $action_term === $id ) { $selectedSubTerms = $sT; } } $postCount = ( $post_count ? " ({$term['count']})" : null ); if ( $action_term && $action_term == $id ) { $termDefaultText = $term['name'] . $postCount; $dataTerm = $id; } if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) { if ( 'NOT IN' === $taxFilterOperator ) { if ( ! in_array( $id, $taxFilterTerms ) && $action_term != $id ) { $htmlButton .= "{$term['name']}{$postCount}{$sT}"; } } else { if ( in_array( $id, $taxFilterTerms ) && $action_term != $id ) { $htmlButton .= "{$term['name']}{$postCount}{$sT}"; } } } else { $htmlButton .= "{$term['name']}{$postCount}{$sT}"; } $i ++; } } $pAllCount = null; if ( $post_count ) { $pAllCount = " ({$pCount})"; if ( ! $action_term ) { $termDefaultText = $termDefaultText . $pAllCount; } } if ( ! $hide_all_button ) { $htmlButton = "" . $allText . "{$pAllCount}" . $htmlButton; } $htmlButton = sprintf( '%s', $htmlButton ); $showAllhtml = ' ' . $termDefaultText . ' '; $data .= $showAllhtml . $htmlButton; $data .= '
' . $selectedSubTerms; } else { $bCount = 0; $bItems = null; if ( ! empty( $terms ) ) { foreach ( $terms as $id => $term ) { $bCount = $bCount + absint( $term['count'] ); $sT = null; if ( $taxHierarchical ) { $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id ); if ( ! empty( $subTerms ) ) { $sT .= "
"; foreach ( $subTerms as $stId => $t ) { $sTPostCount = ( $post_count ? " ({$t['count']})" : null ); $sT .= "{$t['name']}{$sTPostCount}"; } $sT .= '
'; if ( $action_term === $id ) { $selectedSubTermsForButton = $sT; } } } $postCount = ( $post_count ? " ({$term['count']})" : null ); $termSelected = null; if ( $isTermSelected && $id == $action_term ) { $termSelected = ' selected'; } if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) { if ( 'NOT IN' === $taxFilterOperator ) { if ( ! in_array( $id, $taxFilterTerms ) ) { $bItems .= "{$term['name']}{$postCount}{$sT}"; } } else { if ( in_array( $id, $taxFilterTerms ) ) { $bItems .= "{$term['name']}{$postCount}{$sT}"; } } } else { $bItems .= "{$term['name']}{$postCount}{$sT}"; } } } $data .= "
"; if ( ! $hide_all_button ) { $pCountH = ( $post_count ? " ({$bCount})" : null ); $data .= "" . $allText . "{$pCountH}"; } $data .= $bItems; $data .= '
'; } } // Author filter. if ( in_array( '_author_filter', $filters ) ) { $filterType = ( ! empty( $_REQUEST['tgp_filter_type'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tgp_filter_type'] ) ) : null ); $post_count = ( ! empty( $_REQUEST['tpg_post_count'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tpg_post_count'] ) ) : null ); $postCountClass = ( $post_count ? ' has-post-count' : null ); $users = get_users( apply_filters( 'tpg_author_arg', [] ) ); $allSelect = ' selected'; $isTermSelected = false; if ( $action_term && $taxFilter ) { $isTermSelected = true; $allSelect = null; } if ( ! $filterType || 'dropdown' === $filterType ) { $data .= "
"; $termDefaultText = $allText; $dataAuthor = 'all'; $htmlButton = ''; $htmlButton .= ''; if ( ! empty( $users ) ) { foreach ( $users as $user ) { if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) { if ( in_array( $user->ID, $filterAuthors ) ) { if ( $action_term == $user->ID ) { $termDefaultText = $user->display_name; $dataTerm = $user->ID; } else { $htmlButton .= "{$user->display_name}"; } } } else { if ( $action_term == $user->ID ) { $termDefaultText = $user->display_name; $dataTerm = $user->ID; } else { $htmlButton .= "{$user->display_name}"; } } } } if ( $isTermSelected ) { $htmlButton .= "" . $allText . "{$pAllCount}"; } $htmlButton .= ''; $showAllhtml = ' ' . $termDefaultText . ' '; $data .= $showAllhtml . $htmlButton; $data .= '
'; } else { $bCount = 0; $bItems = null; if ( ! empty( $users ) ) { foreach ( $users as $user ) { if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) { if ( in_array( $user->ID, $filterAuthors ) ) { $bItems .= "ID}'>{$user->display_name}"; } } else { $bItems .= "ID}'>{$user->display_name}"; } } } $data .= "
"; if ( ! $hide_all_button ) { $pCountH = ( $post_count ? " ({$bCount})" : null ); $data .= "" . $allText . "{$pCountH}"; } $data .= $bItems; $data .= '
'; } } if ( in_array( '_search', $filters ) ) { $data .= '
'; $data .= sprintf( '', esc_html__( 'Search...', 'the-post-grid' ) ); $data .= "🔍"; $data .= ""; $data .= '
'; } if ( in_array( '_order_by', $filters ) ) { $wooFeature = ( 'product' === $postType ? true : false ); $orders = Options::rtPostOrderBy( $wooFeature ); $action_orderby = ( ! empty( $args['orderby'] ) ? trim( $args['orderby'] ) : 'none' ); if ( 'none' === $action_orderby ) { $action_orderby_label = esc_html__( 'Sort By None', 'the-post-grid' ); } elseif ( in_array( $action_orderby, array_keys( Options::rtMetaKeyType() ) ) ) { $action_orderby_label = esc_html__( 'Meta value', 'the-post-grid' ); } else { $action_orderby_label = $orders[ $action_orderby ]; } if ( 'none' !== $action_orderby ) { $orders['none'] = esc_html__( 'Sort By None', 'the-post-grid' ); } $data .= '
'; $data .= " {$action_orderby_label} "; $data .= ''; foreach ( $orders as $orderKey => $order ) { $data .= '' . $order . ''; } $data .= ''; $data .= '
'; } if ( in_array( '_sort_order', $filters ) ) { $action_order = ( ! empty( $args['order'] ) ? strtoupper( trim( $args['order'] ) ) : 'DESC' ); $data .= '
'; $data .= " "; $data .= '
'; } $data .= "
$selectedSubTermsForButton
"; } $data .= "
"; if ( $gridQuery->have_posts() ) { if ( $isCarousel ) { $cOpt = ! empty( $_REQUEST['carousel_property'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST['carousel_property'] ) ) : []; $slider_js_options = apply_filters( 'rttpg_slider_js_options', [ 'speed' => ! empty( $_REQUEST['tpg_carousel_speed'] ) ? absint( $_REQUEST['tpg_carousel_speed'] ) : 250, 'autoPlayTimeOut' => ! empty( $_REQUEST['tpg_carousel_autoplay_timeout'] ) ? absint( $_REQUEST['tpg_carousel_autoplay_timeout'] ) : 5000, 'autoPlay' => in_array( 'auto_play', $cOpt ) ? true : false, 'stopOnHover' => in_array( 'stop_hover', $cOpt ) ? true : false, 'nav' => in_array( 'nav_button', $cOpt ) ? true : false, 'dots' => in_array( 'pagination', $cOpt ) ? true : false, 'loop' => in_array( 'loop', $cOpt ) ? true : false, 'lazyLoad' => in_array( 'lazyLoad', $cOpt ) ? true : false, 'autoHeight' => in_array( 'auto_height', $cOpt ) ? true : false, 'rtl' => in_array( 'rtl', $cOpt ) ? true : false, ] ); $data .= sprintf( '
', htmlspecialchars( wp_json_encode( $slider_js_options ) ) ); } $isotope_filter = null; if ( $isIsotope ) { $isotope_filter = isset( $_REQUEST['isotope_filter'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['isotope_filter'] ) ) : null; $isotope_dropdown_filter = isset( $_REQUEST['isotope_filter_dropdown'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['isotope_filter_dropdown'] ) ) : null; $selectedTerms = []; if ( isset( $_REQUEST['post_filter'] ) && in_array( 'tpg_taxonomy', $_REQUEST['post_filter'] ) && isset( $_REQUEST['tpg_taxonomy'] ) && in_array( $isotope_filter, $_REQUEST['tpg_taxonomy'] ) ) { $selectedTerms = ( isset( $_REQUEST[ 'term_' . $isotope_filter ] ) ? array_map( 'sanitize_text_field', wp_unslash( $_REQUEST[ 'term_' . $isotope_filter ] ) ) : [] ); } global $wp_version; if ( version_compare( $wp_version, '4.5', '>=' ) ) { $terms = get_terms( $isotope_filter, [ 'meta_key' => '_rt_order', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'hide_empty' => false, 'include' => $selectedTerms, ] ); } else { $terms = get_terms( $isotope_filter, [ 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false, 'include' => $selectedTerms, ] ); } $data .= '
'; $htmlButton = $drop = null; $fSelectTrigger = false; if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) { foreach ( $terms as $term ) { $tItem = ! empty( $_REQUEST['isotope_default_filter'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['isotope_default_filter'] ) ) : null; $fSelected = null; if ( $tItem == $term->term_id ) { $fSelected = 'selected'; $fSelectTrigger = true; } $htmlButton .= sprintf( '', esc_attr( $term->slug ), $fSelected ? ' ' . $fSelected : '', $term->term_id, $term->name ); $drop .= ""; } } if ( empty( $_REQUEST['isotope_filter_show_all'] ) ) { $fSelect = ( $fSelectTrigger ? null : 'class="selected"' ); $htmlButton = "' . $htmlButton; $drop = "" . $drop; } $filter_count = ! empty( $_REQUEST['isotope_filter_count'] ); $filter_url = ! empty( $_REQUEST['isotope_filter_url'] ); $htmlButton = "
{$htmlButton}
"; if ( $isotope_dropdown_filter ) { $data .= ""; } else { $data .= $htmlButton; } if ( ! empty( $_REQUEST['isotope_search_filter'] ) ) { $data .= ""; } $data .= '
'; $data .= "
"; } $l = $offLoop = 0; $offsetBigHtml = $offsetSmallHtml = null; $tgCol = 2; if ( 'layout4' === $layout ) { $tgCol = round( 12 / $dCol ); } $gridPostCount = 0; $arg['totalPost'] = $gridQuery->post_count; while ( $gridQuery->have_posts() ) : $gridQuery->the_post(); if ( $tgCol == $l ) { if ( $this->l4toggle ) { $this->l4toggle = false; } else { $this->l4toggle = true; } $l = 0; } $arg['postCount'] = $gridPostCount ++; $pID = get_the_ID(); $arg['pID'] = $pID; $arg['title'] = Fns::get_the_title( $pID, $arg ); $arg['pLink'] = get_permalink(); $arg['toggle'] = $this->l4toggle; $arg['author'] = '' . get_the_author() . ''; $comments_number = get_comments_number( $pID ); $comments_text = sprintf( '(%s)', number_format_i18n( $comments_number ) ); $arg['date'] = get_the_date(); $arg['excerpt'] = Fns::get_the_excerpt( $pID, $arg ); $arg['categories'] = get_the_term_list( $pID, 'category', null, ', ' ); $arg['tags'] = get_the_term_list( $pID, 'post_tag', null, ', ' ); $arg['post_count'] = get_post_meta( $pID, Fns::get_post_view_count_meta_key(), true ); $arg['responsiveCol'] = [ $dCol, $tCol, $mCol ]; if ( $isIsotope ) { $termAs = wp_get_post_terms( $pID, $isotope_filter, [ 'fields' => 'all' ] ); $isoFilter = []; if ( ! empty( $termAs ) ) { foreach ( $termAs as $term ) { $isoFilter[] = 'iso_' . $term->term_id; $isoFilter[] = 'rt-item-' . esc_attr( $term->slug ); } } $arg['isoFilter'] = ! empty( $isoFilter ) ? implode( ' ', $isoFilter ) : ''; } $deptClass = null; if ( ! empty( $deptAs ) ) { foreach ( $deptAs as $dept ) { $deptClass .= ' ' . $dept->slug; } } if ( comments_open() ) { $arg['comment'] = "{$comments_text} "; } else { $arg['comment'] = "{$comments_text}"; } $imgSrc = null; $arg['smallImgSrc'] = ! $fImg ? Fns::getFeatureImageSrc( $pID, $fSmallImgSize, $mediaSource, $defaultImgId, $customSmallImgSize ) : null; if ( $isOffset ) { if ( 0 === $offLoop ) { $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc( $pID, $fImgSize, $mediaSource, $defaultImgId, $customImgSize ) : null; $arg['offset'] = 'big'; $offsetBigHtml = Fns::get_template_html( 'layouts/' . $layout, $arg ); } else { $arg['offset'] = 'small'; $arg['offsetCol'] = [ $dCol, $tCol, $mCol ]; $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc( $pID, 'thumbnail', $mediaSource, $defaultImgId, $customImgSize ) : null; $offsetSmallHtml .= Fns::get_template_html( 'layouts/' . $layout, $arg ); } } else { $arg['imgSrc'] = ! $fImg ? Fns::getFeatureImageSrc( $pID, $fImgSize, $mediaSource, $defaultImgId, $customImgSize ) : null; $data .= Fns::get_template_html( 'layouts/' . $layout, $arg ); } $offLoop ++; $l ++; endwhile; if ( $isOffset ) { $oDCol = Fns::get_offset_col( $dCol ); $oTCol = Fns::get_offset_col( $tCol ); $oMCol = Fns::get_offset_col( $mCol ); if ( 'offset03' === $layout || 'offset04' === $layout ) { $oDCol['big'] = $oTCol['big'] = $oDCol['small'] = $oTCol['small'] = 6; $oMCol['big'] = $oMCol['small'] = 12; } elseif ( 'offset06' === $layout ) { $oDCol['big'] = 7; $oDCol['small'] = 5; } $data .= "
{$offsetBigHtml}
"; $data .= "
{$offsetSmallHtml}
"; } if ( $isIsotope || $isCarousel ) { $data .= '
'; // End isotope / Carousel item holder. if ( $isCarousel ) { if ( in_array( 'pagination', $cOpt ) ) { $data .= '
'; } $data .= '
'; if ( in_array( 'nav_button', $cOpt ) ) { $data .= '
'; } } } } else { $not_found_text = isset( $_REQUEST['tgp_not_found_text'] ) && ! empty( $_REQUEST['tgp_not_found_text'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tgp_not_found_text'] ) ) : esc_html__( 'No post found', 'the-post-grid' ); $data .= '

' . $not_found_text . '

'; } $data .= $preLoaderHtml; $data .= '
'; // End row. $htmlUtility = null; if ( $pagination && ! $isCarousel ) { if ( $isOffset || $isGridHover ) { $posts_loading_type = 'page_prev_next'; $htmlUtility .= "
"; } else { if ( 'pagination' === $posts_loading_type ) { if ( $isGrid && empty( $filters ) ) { $htmlUtility .= Fns::rt_pagination( $gridQuery, $args['posts_per_page'] ); } } elseif ( 'pagination_ajax' === $posts_loading_type && ! $isIsotope ) { if ( $isGrid ) { $htmlUtility .= "
"; } else { $htmlUtility .= Fns::rt_pagination( $gridQuery, $args['posts_per_page'], true ); } } elseif ( 'load_more' === $posts_loading_type ) { $load_more_btn_text = ( ! empty( $_REQUEST['load_more_text'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['load_more_text'] ) ) : '' ); $load_more_text = $load_more_btn_text ? $load_more_btn_text : esc_html__( 'Load More', 'the-post-grid' ); if ( $isGrid ) { $htmlUtility .= "
" . esc_html( $load_more_text ) . "
"; } else { $htmlUtility .= "
'; } } elseif ( 'load_on_scroll' === $posts_loading_type ) { if ( $isGrid ) { $htmlUtility .= "
"; } else { $htmlUtility .= '
'; } } } } if ( $htmlUtility ) { $l4toggle = null; if ( 'layout4' === $layout ) { $l4toggle = 'data-l4toggle="' . $this->l4toggle . '"'; } if ( $isGrid || $isOffset || $isWooCom ) { $data .= '
' . $htmlUtility . '
'; } else { $data .= '
' . $htmlUtility . '
'; } } $data .= '
'; // container rt-tpg. } else { $msg = esc_html__( 'Session Error !!', 'the-post-grid' ); } wp_send_json( [ 'error' => $error, 'msg' => $msg, 'data' => $data, ] ); die(); } }