Im trying to get a load more function to work with a custom post type on an archive page.

I use this plugin and customized it a bit so it works with a custom post type. http://www.problogdesign.com/wordpress/load-next-wordpress-posts-with-ajax/

Currently pagination doesn't work so that the plugin can't load more items. It says "inbeeld/page/2/ 404 (Not Found)". So my question is why does the pagination do not work?

This is the register_post_type code.

$inbeeld_args = array(
    'label' => __('In Beeld'),
    'singular_label' => __('In Beeld'),
    'public' => true,
    'query_var' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => array("slug" => "inbeeld", 'with_front'=> false, "pages" => true  ),
    'has_archive' => true,
    'supports' => array('title', 'editor', 'taxonomy', 'thumbnail'),
    'taxonomies' => array('teams'),
    'add_new' => _x('Nieuw', 'In Beeld'),
    'add_new_item' => __('Voeg Nieuw In Beeld Toe'),
    'edit_item' => __('Bewerk In Beeld'),
    'new_item' => __('Nieuw In Beeld'),
    'view_item' => __('Bekijk In Beeld'),
    'search_items' => __('Doorzoek In Beeld'),
    'not_found' =>  __('No In Beeld found'),
    'not_found_in_trash' => __('No In Beeld found in Trash'),
    'pages' => true

And this is my loop. I removed some code that nothing has to do with my question.


$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$query = new WP_query(array('post_type' => 'inbeeld','paged' => $paged, 'posts_per_page' => 2  ));
while ($query->have_posts()) : $query->the_post();
    <?php the_title(); ?>
<?php endwhile; wp_reset_query(); ?>

The problem with pagination was fixed by removing the wp_query loop and using the normal loop.

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php endwhile; endif; ?>

The problem with the "load more" plugin was fixed by using the right classname to load the items. And change this in the php of the plugin.

$paged = ( get_query_var('paged') > 1 ) ? get_query_var('paged') : 1;   
$args = array('post_type' => 'inbeeld', 'paged' => get_query_var('paged') );    
$query = new WP_Query($args);
$max = $query->max_num_pages;

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.