Random error in my post loop?
-
On this page of my website:
https://animewolf.tv/series/code-geass/
You can see everything under “English Dubbed” links to episode 10, I’m not sure why this is, as I’ve edited the page, but there isn’t any extra episode 10’s so I’m not sure why my loop is looping only episode 10, as you can tell on every other page/series page they loop into episode lists fine, but this one is a little messed up.
The loop is handled from a custom post type called ‘anime’
the plugin I’m using is called AnimeScrape
https://www.animescrape.com/documentation/
However it’s paid only so you probably won’t get much out of it other than some of the code references from it…
Here is my page template:
<?php function bubbleSort(array $arr) { $sorted = false; while (!$sorted) { $sorted = true; for ($i = 0; $i < count($arr)-1; ++$i) { $current = $arr[$i]; $next = $arr[$i+1]; $subdub = $next->subdub_flag; $epnum_next = $next->epnum_int; $epnum_current = $current->epnum_int; $epnum_next = explode("-", $epnum_next); $epnum_current = explode("-", $epnum_current); if ($epnum_next[0] < $epnum_current[0]) { $arr[$i] = $next; $arr[$i+1] = $current; $sorted = false; } if (($epnum_next[0] == $epnum_current[0]) && ($subdub == 0 )) { $arr[$i] = $next; $arr[$i+1] = $current; $sorted = false; } } } return $arr; } get_header(); $term = get_term_by('slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); $id = $term->term_id; $series = get_option("taxonomy_$id"); $img = $series['image_term_meta']; $options = get_option('animeslider_theme_options'); if( $options['show_slider'] ){ ?> <div class="jumbotron"> <h2><?php echo $term->name; ?></h2> </div><!-- Featured Jumbotron w/Slider --> <?php } else { ?> <div class="container"> <div class="jumbotron"> <div class="container"> <h2><?php the_title(); ?></h2> </div> </div> </div><!-- Featured Jumbotron w/o Slider --> <?php } ?> <div class="container"> <!-- BEGIN CPMSTAR TWO-SIDED ASYNCHRONOUS SITESKIN CODE 20130626 --> <script type="text/javascript"> var cpmstar_siteskin_settings = { pid: 54233, //your poolid centerWidth: '1170px', //distance IN PIXELS of ad from left side of page, e.g. "800px" fixed: '1', //fix ads near top of screen: "0" to allow ads to scroll with page topPos: '110px', //optionally shift the ad down from top of page zIndex: 1 //adjust layering of ad vs. other page elements }; (function(){var t=document.createElement('script');t.type='text/javascript';t.async=1;t.src=(document.location.protocol == "https:"?"//server":"//cdn") + ".cpmstar.com/cached/js/siteskin_v100.pack.js";var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(t,s);})(); </script> <!-- END CPMSTAR SITESKIN CODE --> <div class="container-fluid left"> <img onError="this.src='https://animewolf.tv/wp-content/uploads/2014/12/wolf.png';" id="cover" src="<?php echo $img; ?>" style="width: 200px; height: 275px;" /> <div class="container right"> <h4><?php echo $term->name . "'s ";?>Synopsis</h4> <p><?php echo $term->description; ?><p><?php $args = array( 'post_type' => 'anime', 'series' => $term->slug, 'post_status' => 'publish', 'posts_per_page' => -1 ); $my_query = new WP_Query( $args ); $eps = array(); $Slinks = array(); $Dlinks = array(); if($my_query->have_posts() ) : while($my_query->have_posts() ) : $my_query->the_post(); $ep = get_post_meta( get_the_ID(), 'episode_data', true ); if( $ep->subdub_flag == 0 ) $Slinks[$ep->episode_id] = get_permalink(); else if( $ep->subdub_flag == 1 ) $Dlinks[$ep->episode_id] = get_permalink(); $eps[] = $ep; endwhile; endif; $SortEps = bubbleSort($eps);?> </div> <div class='spacer'> <?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<p id="breadcrumbs">','</p>'); } ?> </div> <table id='seriesInfo'> <tr><th>Genres:</th> <td> <?php echo '<p class="genre-listing">'; ?> <?php $i = 0; $genres = explode( ', ', $series['genre_term_meta'] ); foreach( $genres as $g ){ if( $i ) echo ', '; else $i = 1; echo $g; } ?> <?php echo '</p>'; ?> </td> </tr> <tr><th>Status:</th> <td class=<?php $status = $series['status_term_meta']; if( $status == 0 ) echo '"on-going">On-going'; else if( $status == 1 ) echo '"completed">Completed'; else if( $status == 2 ) echo '"cancelled">Cancelled'; ?> </td> </tr> </table> <div class='spacer'></div> <table id="epTable"> <thead><tr style="border-bottom:1px solid black;"> <th>EP#</th> <th>Episode Title</th> <th>English Subbed</th> <th>English Dubbed</th></tr> </thead><tbody class="small"><?php $lastEp = 0; for($i = 0; $i < count($SortEps); $i++) { if( $SortEps[$i]->epnum_int != $lastEp ){ $lastEp = $SortEps[$i]->epnum_int; ?> <tr class="listing"><td><?php echo $lastEp; ?></td> <td><?php echo $SortEps[$i]->wordtitle; ?></td> <td><?php if($SortEps[$i]->subdub_flag == 0 ){ echo "<a title='Watch ". $term->name ." Episode ". $lastEp ." Subbed Online' href='" . $Slinks[$SortEps[$i]->episode_id] . "'>Watch Subbed</a>"; }else echo "Unavailable"; ?></td> <td><?php if( $i < count($SortEps) - 1 ){ if($SortEps[$i+1]->epnum_int == $lastEp && $SortEps[$i+1]->subdub_flag == 1) $i++; } if( $SortEps[$i]->subdub_flag == 1 ){ echo "<a title='Watch ". $term->name ." Episode ". $lastEp ." Dubbed Online' href='" . $Dlinks[$SortEps[$i]->episode_id] . "'>Watch Dubbed</a>"; }else echo "Unavailable"; ?></td></tr><?php } } ?> </tbody> </table> </div> </div><!-- Main Container --> <?php get_footer(); ?>
If anyone can help me that would be great, or if there is a way to maybe re-fresh the loop or something? I’m not entirely sure what’s wrong to be honest..
- The topic ‘Random error in my post loop?’ is closed to new replies.