How to increase the number posts that displays by a hierarchical taxonomy? (HTTP ERROR 500)

HTTP ERROR 500

I got HTTP ERROR 500 when I tried to get all the posts from a hierarchical taxonomy which is category.

I have a page and in this page I want to display all the posts. This page and those posts have same category which called ex. hello.

In the page I used this query below to output the posts from the category which this page have.

<div class="box">
                            <?php
                                $category = get_the_category();
                                if($category->category_parent > 0){
                                    echo $category[0]->cat_name;
                                }

                                $args = array(
                                    'post_type' => 'post',
                                    'tax_query' => array(
                                        'relation' => 'AND',
                                        array(
                                            'taxonomy' => 'category',
                                            'field'    => 'slug',
                                            'terms'    => array( $category[0]->cat_name ),
                                        ),
                                        array(
                                            'taxonomy' => 'post_format',
                                            'field'    => 'slug',
                                            'terms'    => array( 'post-format-video' ),
                                        ),
                                    ),
                                    'order'   => 'ASC',
                                    'nopaging' => true,
                                );

                                $the_query = new WP_Query( $args );

                                while ( $the_query->have_posts() ) {
                                        $the_query->the_post();?>
                                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><h3><?php the_title(); ?></h3></a>
                                <?php  }

                                // Restore original Post Data
                                wp_reset_postdata();
                            ?>
                        </div>

The query worked fine with the other categories in the other pages which have maximum 300 posts. But category hello have more than 900 posts and when I display theme with the same query I got HTTP ERROR 500.

The category hello is a child of a category called series but this is not the reason of this problem but I wanted just to clarify the issue for you.

Note: When the category hello had 500 posts the page worked and the posts are displaying but the page take more than 3 seconds to load. So the more posts I add to the category the more time the page need to load and in the end if the posts became more the page give me HTTP ERROR 500.

Note: I tried the code on loaclhost and everything worked no errors at all.

Read more here:: How to increase the number posts that displays by a hierarchical taxonomy? (HTTP ERROR 500)

Leave a Reply

Your email address will not be published. Required fields are marked *