Put your code in the pastebin and submit it and post the link to it here.
some further reading: http://wordpress.org/tags/custom-post-type-pagination
Exactly what code do you need to see? My functions.php is nearly a 1,000 lines long and much of it spurious to this situation. Are there specific custom post type functions you need to see? That’s why I posted the register function (so you can see the rewrite value) and the template.
I’ll read the pagination posts you reference. Thank you for that.
I had this problem I got round it two ways. I created a CPT archive page which is the format of archive-CPT name
change CPT to your post type and then set the loop query to post_type=CPT name.
So for portfolio you’d have
archive-portfolio.php
and your query as:
query_posts( ‘post_type=portfolio’)
Also make sure you refresh your permalinks, just saving is enough. As you need to ensure WP is aware of the CPTs.
Sorry, keesie, see now that my code was whacked in my original post. Here’s the Pastebin URL:
http://pastebin.com/fSt99VQP
@csd_images, I think that I’ve tried your approach but will try again. Not finding anything clicking down keesie’s tag list, so far.
Thanks.
Part of the mystery solved by reverting permalinks to expose the query string values. The “Older Stories” link goes to a page_id value that is for the page instead of a content type. So the querystring values are:
?page_id=30&paged=2
Any ideas the reason the content type is not passed?
I have an archive template with the filename including the content type name, with the generic WP calls to header, sidebar, and footer, as well as basic content. No wp_query.
Question: If I call my new content type URL, I should see the basic content, correct? That’s how I would test the right template is being called?
My problem is that doing this generates a 404 page. I want to understand how WP got to that 404 page. By first not obsessing about the wp_query code but instead trying to figure out how to get WP to call the correct template.
Any ideas how to determine the path WP takes to get to the 404 page?
The pastebin code is still valid, above. The register_post_type name is ‘faq’, the URL is /faq, and the archive file is archive-faq.php. None of that appears to work: I get a 404 page all the time.
Appreciate any help debugging this problem.
Update: With permalinks “off” to show the querystring, I set the URL to ?post_type=faq then added “xyz” to my archive-faq.php, archive.php, and index.php files, one by one, to match the template hierarchy WP follows. For some reason, my WP install ignores archive-faq.php and archive.php and only uses the index.php template. That’s the mystery I’m trying to solve, for now: how to get WP to use the archive-faq.php template.
try resaving your permalink structure under Settings > Permalinks
If you also have a Page called “faq” this could also cause troubles.
@keesie I’ve reset permalinks all the time, every test. I also don’t have an FAQ page (I should be so lucky!).
is your archive template called: archive-faq.php? I will try your code on my testserver
Yes. The -typename.php is the archive file.
The problem appears to be changing the slug from the value used to register the content type. Specifically, if I set the rewrite value in $args to ‘faqs’ while the content type is registered as ‘faq’ these problems happen. If I set rewrite to true, WP happily displays the index.php template (still ignoring the archive-faq.php and archive.php templates).
Ideally I want to have the slug and content type name different so that my content types will be custom to the install, not likely to be stepped on by some future WP upgrade or plugin that offers a content type called ‘faq’ or ‘faqs’.
My goal is to come up with an instance of creating a content type that works to add/edit/delete content, display an archive page, and display a detail/single page. Displaying the archive page eludes me.
Appreciate your help.
If I register with this it works:
function faqs_register() {
$labels = array(
'name' => _x('FAQs', 'post type general name'),
'singular_name' => _x('FAQ Item', 'post type singular name'),
'add_new' => _x('Add New', 'FAQ item'),
'add_new_item' => __('Add New FAQ'),
'edit_item' => __('Edit FAQ'),
'new_item' => __('New FAQ'),
'view_item' => __('View FAQ'),
'search_items' => __('Search FAQ'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'_builtin' => false,
'query_var' => true,
'rewrite' => array('slug' => 'faqs', 'with_front' => false),
'menu_icon' => get_stylesheet_directory_uri() . '/icons/faqs.png',
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 4,
'supports' => array('title','editor','thumbnail'),
);
register_post_type( 'faq' , $args );
}
Interesting. It works with permalinks on but not with the default permalinks. Even better, the URL /faqs now calls the archive-faq.php template. So thank you!
For the record, the rewrite value was the only thing you changed in $args?
What doesn’t work? the pagination?
For the record, the rewrite value was the only thing you changed in $args?
I just took the $args of an old custom post type I had and replaced your $args with it.
also: 'has_archive' => true,
… and I notice _builtin is added to $args.
What doesn’t work is the underlying problem of pulling the correct template. Default permalinks uses index.php in all cases if I use the content type name registered in functions.php. When I switch to a defined permalink, the /faqs URL pulls from archive-faq.php.
Now that /faqs pulls from the right template, I can add content and see if the /page/2/ pagination works.
Let you know how it goes.
are you using an url like this “http://yoursite.com/?post_type=faq” when viewing the faq archive with default permalinks