false, 'serie_id' => null, 'classes' => null, 'category' => false, 'quantity' => 12, 'offset' => 0, 'current_video_id' => null ), $atts ) ); ob_start(); $offset = (int)$offset; if(!is_numeric($offset)) { $offset = 0; } /** * Query preparation */ if(null !== $serie_id && false !== $serie_id && '' !== $serie_id){ /** * Case 1: we extract the videos from a playlist */ $episodes = get_post_meta( $serie_id, 'vlogger_seriesvideos', true ); $ep_id = array(); foreach($episodes as $e){ $ep_id[] = $e['vlogger_episodes'][0]; } $argsList = array( 'post__in'=> $ep_id, 'posts_per_page' => (int)$quantity, 'post__not_in' => $current_video_id, 'offset' => $offset, 'ignore_sticky_posts' => 1, 'meta_query' => array( array( 'key' => '_thumbnail_id', 'compare' => 'EXISTS' ), ) ); } else { /** * Case 2: we extract similar videos, then other ones in order */ $argsList = array( 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => false, 'posts_per_page' => (int)$quantity, 'paged' => 1, 'offset' => $offset, //'post_format' => 'post-format-video', 'post__not_in'=> array($current_video_id), 'ignore_sticky_posts' => 1, 'meta_query' => array( array( 'key' => '_thumbnail_id', 'compare' => 'EXISTS' ), ) ); /** * Add category parameters to query if any is set */ if (false !== $category && 'all' !== $category) { $argsList[ 'tax_query'] = array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => array(esc_attr($category)), 'operator'=> 'IN' //Or 'AND' or 'NOT IN' ) ); } $secondaryQuery = $argsList; // used if we have too few results /** * * Check if we have a taxonomy result and add to query * */ $related_taxonomy = 'category'; $terms = get_the_category( get_the_id() ); $term_ids = false; if( !is_wp_error( $terms ) ) { if(is_array($terms)) { $term_ids = wp_list_pluck($terms,'term_id'); if ($term_ids) { $argsList['tax_query'] = array( array( 'taxonomy' => $related_taxonomy, 'field' => 'id', 'terms' => $term_ids, 'operator'=> 'IN' ) ); } } } } /** * We want only stuff with a thumbnail otherwise it looks ugly */ $argsList[ 'meta_query'] = array( array( 'key' => '_thumbnail_id', 'compare' => 'EXISTS' ) ); // ========== QUERY BY ID ================= if($id){ $idarr = explode(",",$id); if(count($idarr) > 0){ $quantity = count($idarr); $argsList = array( 'post__in'=> $idarr, 'orderby' => 'post__in', 'ignore_sticky_posts' => 1 ); } } // ========== QUERY BY ID END ================= $custom_posts = new WP_Query($argsList); $total_results = $custom_posts->found_posts; $found_array = array( $current_video_id); if ( $custom_posts->have_posts() ) : if(null !== $serie_id && false !== $serie_id && '' !== $serie_id){ add_filter("the_permalink", $vlogger_filter_x = function( $url ) use ( $serie_id ){ return add_query_arg("vlogger_serie_in", $serie_id, $url); }, 99, 2); } ?>