0

i have a loop that fetch custom post type from the database now when i go to the page the data doesnt appear but when i refresh the page 2 times the data shows here is the code:

    <div class="expertise-menu">

            <?php
    echo get_the_id();
            $args = array(
                'posts_per_page' => -1,
                'post_type'      => 'syllabus',
                array(
                    'key'     => 'related_expertise',
                    'compare' => 'LIKE',
                    'value'   =>  get_the_id() 
                )
            );

            $syllabus = new WP_Query($args);
            if($syllabus->have_posts()) {
                while( $syllabus->have_posts()) {
                            $syllabus->the_post(); 
                ?>
            <div class="expertise-menu__box" data-expertise="<?= get_field("related_expertise")[0]->post_name; ?>">
                <input type="checkbox" class="expertise-menu__input"
                    name="<?= get_field("related_expertise")[0]->post_name; ?>" id="<?= get_the_id(); ?>">
                <label for="<?= get_the_id(); ?>" class="expertise-menu__label">
                    <span class="svg-box">
                        <svg viewBox="0 0 100 100">
                            <path class="svg-rect"
                                d="M82,89H18c-3.87,0-7-3.13-7-7V18c0-3.87,3.13-7,7-7h64c3.87,0,7,3.13,7,7v64C89,85.87,85.87,89,82,89z" />
                            <polyline class="svg-check" points="25.5,53.5 39.5,67.5 72.5,34.5 " />
                        </svg>
                    </span>

                    <a href="<?= get_the_permalink(); ?>" class="expertise-menu__link">
                        <span class="expertise-menu__text"><?= get_the_title(); ?></span>
                        <span
                            class="expertise-menu__text expertise-menu__text--sub"><?= get_field('syllabus_code'); ?></span>
                    </a>
                    <span class="expertise-menu__arrow">
                        <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-chevron-right"
                            fill="currentColor" xmlns="http://www.w3.org/2000/svg">
                            <path fill-rule="evenodd"
                                d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z" />
                        </svg>
                    </span>
                </label>
            </div>
            <?php } wp_reset_query(); ?>
            <?php } ?>
        </div>
        <!-- Expertise Menu END -->
0

found the solution the problem was the "posts_per_page" it made my website crash on that specific section and also in wp-config.php added

define( 'WP_MEMORY_LIMIT', '256M' );

and it solved my problem

2
  • Possibly due to -1 pulling all the posts. This may be too much to handle for some server. It's almost always recommended to use a high upper limit such as 200 to avoid any type of crashing.
    – Howdy_McGee
    Aug 4 '20 at 16:59
  • yes also that solved my problem thank you! Aug 4 '20 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.