0

I do have a problem with a custom post pagination. I search through this site and googled the whole day yesterday, and found nothing that was similar to what I experience (or I'm getting blind...).

Here is my custom post "recipe":

register_post_type( 'recipe', array(
'labels' => array(
    'name'               => __('Recipes'),
    'singular_name'      => __('Recipe'),
    'add_new'            => __('Add New'),
    'add_new_item'       => __('Add new Recipe'),
    'view_item'          => __('View Recipe'),
    'edit_item'          => __('Edit Recipe'),
    'new_item'           => __('New Recipe'),
    'view_item'          => __('View Recipe'),
    'search_items'       => __('Search Recipes'),
    'not_found'          => __('No Recipes found'),
    'not_found_in_trash' => __('No Recipes found in Trash'),
),
'public'        => true,
'show_ui'       => true,
'hierarchical'  => true,
'supports'      => array('title', 'editor', 'thumbnail'),
'menu_position' => 100,
'menu_icon'     => get_stylesheet_directory_uri() . '/images/icon_recipe.png',
'rewrite'       => array(
    "slug"       => "recipe",
    "with_front" => false,
            "pages"      => true
)
) );

I need to load 6 recipes on my recipe page, and then I use jQuery to load the next 6 in AJAX. The code actually grab the "next page" URL (that is hidden in my page) to perform this.

The problem is that it keeps loading the first 6 recipes, despite the fact that the url is correct (/recettes/page/2/).

When I try to load this page directly in the address bar, it redirects to /recettes/ (that is my first page). Even when I put a die("test") at the top of my template file, it never gets there. Could it be only related to the URL rewriting?

Here is my .htaccess file:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

The strange thing is that the same mechanism works for the news section... Any ideas? Thanks a lot for your help!

Matt

PS: here is the page, if you want to have a look: http://www.francoischartier.ca/recettes/

PPS: and this is the news section that works: http://www.francoischartier.ca/chartier/nouvelles/

Here is the query in the page template for recipes:

            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            $args = array(
                'post_type'      => 'recipe',
                'posts_per_page' => 6,
                'order'          => 'ASC',
                'orderby'        => 'post_title',
                'tax_query'      => array(),
                'paged'          => $paged,
                                    'caller_get_posts' => 1
            );
1

They're not the same. Your news page is the posts page, and your recipes page is a page post type where you've used a custom query to load the posts. I can see that by looking at the classes being added to the body tag. I presume that your custom query has no pagination parameters being passed to it, but you'll have to show us the code in the template to confirm.

If you were to set has_archive to true when you register your post type and use the post type archive page instead of a custom query, your AJAX pagination will probably work.

  • Hi Milo, and thanks for your answer. You're right, I'm using a specific template to display the recipes' page. I've updated the question with the query performed in the template. I'll try the post type "page" with "has_archive" = true to see if it works. – Boute Jun 13 '13 at 18:30
  • I've change the way I register the post and added 'capability_type' => 'page','has_archive' => true. But it still doesn't work... – Boute Jun 13 '13 at 18:39
  • you have to point to that archive instead of the page you're currently using. if you want the archive at recettes then set has_archive to recettes and remove the page. or for testing purposes, try just visiting recipe, which is where your archive page is now located. – Milo Jun 13 '13 at 19:13
  • Nope, didn't work either... – Boute Jun 17 '13 at 14:17
  • I installed the whole site on my computer (WAMP), and surprisingly, it works there, but not online. Any idea of what can be wrong? – Boute Jun 17 '13 at 14:18
0

Finally, I was able to solve it. The problem was caused by a plugin, 404 Redirected. It catched my URL and decided that it needed to add a 301 redirection on my URL and then send it to the URL without pagination...

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.