$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 = '
' . $not_found_text . '
'; } $data .= $preLoaderHtml; $data .= '