• Resolved leiho

    (@leiho)


    Hello guys,
    I’m stuck with my sister’s website. I’m using CPT UI to displays projects thumbails for her portfolio. It was all going swimmingly till I added the 11th item. It doesn’t display, not trace of any element I added after the 10th?
    What can be the issue? I must confess Im php/wp newb, I can read it a bit but i don’t see anything wrong with the loop query. This is confusing to me.
    If anyone has a clue, it would be much appreciated!
    cheers

    Here is my code :

    <?php $loop = new WP_Query( array('post_type' => 'project_thumbnails', 'orderby' => 'post-id', 'order' => 'ASC'));  ?>
     <?php while( $loop->have_posts() ) : $loop->the_post(); ?>
     <?php $image = get_field('project_image'); $url = $image['url']; $alt = $image['alt'];   ?>
    
    <a href="<?php the_field('project_url'); ?>">
    <div class="project <?php the_field('project_category'); ?>">
    <div class="project-info">                    
    <h1><?php the_field('project_title'); ?></h1>         
    <h2><?php the_field('project_subtitle'); ?></h2>
    </div>
    <img src="<?php echo $url; ?>" alt="<?php echo $alt; ?>" >
    </div>
    </a>
    <?php endwhile; ?>
    • This topic was modified 8 years, 1 month ago by leiho.
Viewing 1 replies (of 1 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Two immediate things I can see contributing.

    1. You’re using the default posts per page value for a WP_Query instance. By default, it’s 10, and controlled by the posts per page setting in Settings > Reading in your admin. You can specify your own value for this spot by passing in an array of arguments like so:

    array('post_type' => 'project_thumbnails', 'orderby' => 'post-id', 'order' => 'ASC', 'posts_per_page' => 25 )
    

    That’d change it to 25 per page. However, see item 2 below.

    2. You’re not providing pagination links. Outside of telling WordPress to fetch ALL of them each time, you’re going to hit your posts per page limit eventually, whether it’s 10, 25, 42, 100, etc. It’s at those points that you want to provide links to move to the next set, say posts 11-20.

    I’d look over https://codex.www.ads-software.com/Next_and_Previous_Links for a general overview, and this https://docs.pluginize.com/article/81-cleanly-done-pagination-with-custom-wpquery-objects regarding some sleuthing I did, which may fit your needs. Not sure exactly where you’re using your custom WP_Query object.

Viewing 1 replies (of 1 total)
  • The topic ‘Only first 10 items of my CPT can display?’ is closed to new replies.