0

I'm finishing a custom layout.

Here's the code of my Custom Post Type

<?php
/* ------------------ [ CUSTOM POST TYPE ] ------------------------- */

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'notizia',
        array(
            'labels' => array(
                'name' => __( 'Notizie' ),
                'singular_name' => __( 'Notizia' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'notizia'),
            'menu_icon' => get_bloginfo('template_directory') . '/images/amministrazione/notizia.png', 
            'supports' => array('title','thumbnail','excerpt','editor','author','custom-fields','comments', 'post-formats')
        )
    );
    register_post_type( 'recensione',
        array(
            'labels' => array(
                'name' => __( 'Recensioni' ),
                'singular_name' => __( 'Recensione' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'recensione'),
            'menu_icon' => get_bloginfo('template_directory') . '/images/amministrazione/software.png', 
            'supports' => array('title','thumbnail','excerpt','editor','author','custom-fields','comments')
        )
    );
}
?>

Here's code for Taxonomy

    <?php
 register_taxonomy(
      'tipologia',
      'recensione',
      array(
         'label' => __( 'Tipologia' ),
         'rewrite' => array( 'slug' => 'tipologia' ),
         'hierarchical' => false
      )
   );
 register_taxonomy(
      'piattaforma',
      'recensione',
      array(
         'label' => __( 'Piattaforma' ),
         'rewrite' => array( 'slug' => 'piattaforma' ),
         'hierarchical' => false
      )
   );
 register_taxonomy(
      'produttore',
      'recensione', 
      array(
         'label' => __( 'Produttore' ),
         'rewrite' => array( 'slug' => 'produttore' ),
         'hierarchical' => false
      )
   );
 register_taxonomy(
      'argomenti',
      'notizia',
      array(
         'label' => __( 'Argomenti Notizia' ),
         'rewrite' => array( 'slug' => 'argomenti' ),
         'hierarchical' => false
      )
   );   
    ?>

I'm trying to put inside archive-recensione.php a normal loop : 12 articles per page + pagination. The problem is that every solution doesn't work at all = 404

This code, for example, is ok for the first 2 pages (it's a test). When you arrive at the third page you have a beautiful 404 :)

<?php 
            $temp = $wp_query; 
            $wp_query = null; 
            $wp_query = new WP_Query(); 
            $wp_query->query('showposts=2&post_type=recensione'.'&paged='.$paged); 
            while ($wp_query->have_posts()) : $wp_query->the_post(); 
        ?>

CONTENT

        <?php endwhile; get_pagination();?>
        <?php  $wp_query = null;$wp_query=$temp;?>

Notes

  • get_pagination (custom function for pagination like wp pagenavi) it's not the error. Already done some troubleshooting with and without).
  • Already tried Monkeyman Rewrite Analyzer, i don't see any problems with the permalink structure.
  • problem solved with plugin Custom Posts Per Page if i use a simple if, while, endwhile, endif but i'm very curious to understand the source of the problem without using this plugin

Do you have any solution ? :)

1

I think your test is flawed.

It is the original query-- the one you save to $temp-- that is important for working out which template loads. You overwrite that and paginate based on that overwritten query. That means that the pagination is out of sync with the original query. When you click a pagination link and then the page loads a query runs that does not have your modifications-- 'showposts=2&post_type=recensione'.'&paged='.$paged-- and that query is used to work out the page to load. In some cases, probably many, the original query can't make sense of the pagination based on the modified query and you get a 404.

I don't know why "Custom Posts Per Page" solves it. I am not familiar with that plugin.

  • Thanks for reply. this means that the rest is correct and theoretically, a correct loop with correct paging, doesn't return 404. Right ? :) – Matteus Jun 27 '13 at 1:00
  • Hopefully, the rest is correct. I'd have to install that code and create some posts to really test it and be sure. – s_ha_dum Jun 27 '13 at 1:47

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.