Support » Developing with WordPress » Why is there an infinite loop in my CPT?

  • Resolved kirasiris

    (@kirasiris)


    I built a CPT for “movies” and I created a custom page for the CPT as well. Somehow the CPT is not working as I want as the only thing it does is an infinite loop and it gives me no errors; i decided to go into the source code and I still get not error(after waiting at least 3mins before it actually stop loading).

    So that’s it, can somebody tell me if there’s an error on this?:

    
    <?php
    /*
    Template Name: movie
    Template Post Type: page
    */
    ?>
    <?php get_header(); ?>
    
            <div class="col-md-12 anime-posts">
    			<?php 
                $movies = new WP_Query(array(
                  'post_type' => 'movies',
                ));
                ?>
    		<?php if($movies->have_posts()) : while($movies->have_posts()) : the_post(); ?>
            	<div class="item col-md-3">
                    	<div class="img">
    						<a href="<?php echo the_permalink(); ?>" class="thumbnail"><?php echo the_post_thumbnail(); ?></a>
                            <div class="badge"><?php echo the_category(','); ?></div>
                        </div>
                        <div class="bottom-info">
                        	<h6><?php echo the_title(); ?></h6>
                       	</div>
               	</div>
    			<?php endwhile; ?>
    			<?php else : ?>
                	<div class="alert alert-danger col-md-12" style="margin-right: 15px; margin-left: 15px;">There's not a single movie yet. Sorry for the inconvenience.</div>
    			<?php endif; ?>
            </div>
    
    <?php get_footer();?>
    

    I really have not idea why is not showing me anything(apart from the infinite loop) in the front end.

    This is how I registered the CPT in the functions.php file:

    
    register_post_type( 'movies', $movie_args );
    

    with $movie_arg being just custom configurations when I made it… if you need to see the whole thing(cpt function), just tell me.

    Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • There’s nothing in that code that sould be giving an infiniate loop, so I’d try looking elsewhere to see what’s happening.

    Can you see what part the system is looping on? Is it the same output over and over gain, or jsut locking up and not displaying anything?

    Moderator bcworkz

    (@bcworkz)

    FWIW, a common cause of infinite loops in WP is improper action or filter callback code where the callback inadvertently invokes its own hook or calls a function which does. For example, “the_title” is hooked with a callback that uses code copied from elsewhere which includes the line apply_filters( 'the_title', $title, $id );. This causes the callback to call itself ad infinitum.

    I don’t know if this is the cause in your case, but it’s something to look for. You can also try deactivating all of your plugins to eliminate complicating factors.

    Thread Starter kirasiris

    (@kirasiris)

    I already fixed it. The I checked everything you guys said but it did not fix it so I tried by changing the name to the spanish version “peliculas” and it finally worked. I really have not idea what caused it(the error) or why did it happen since it was not the first time in which I create a “movies” cpt but oh well, is fixed now.

    NOTE: The infinite loop was not showing me nothing, the only thing it did was making the windows(from the browser) bigger…. as if it was a infinite loop, without showing nothing.

    Thanks, I will mark the question as solved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Why is there an infinite loop in my CPT?’ is closed to new replies.