Hello everybody,
I have a real strange problem here! I've registered a own Custom-Post-Type named "work". Like this:
<?php function post_type_work() {
register_post_type(
'work',
array('label' => __('Work'),
'singular_label' => __('Work'),
'public' => true,
'show_ui' => true,
'_builtin' => false,
'taxonomies' => array('workcat,worktype'),
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array("slug" => "work/casestudy",'with_front'=>false),
'supports' => array('title','editor','trackbacks','custom-fields','excerpt','thumbnail'),
'menu_position' => 4
)
);
register_taxonomy( 'workcat', 'work', array( 'hierarchical' => true, 'label' => __('Work-Categories'), 'singular_label' => 'Work-Category', 'rewrite' => array('slug' => 'work'), 'query_var' => true) );
register_taxonomy( 'worktype', 'work', array( 'hierarchical' => false, 'label' => __('Worktype'), "rewrite" => true,'query_var' => true) );
}
add_action('init','post_type_work');
?>
Please especially check this line: 'rewrite' => array("slug" => "work/casestudy",'with_front'=>false),
As you can see, I also registered two taxonomies which belong to my new Custom-Post-Type. Now I've created a page which is ALSO named "work". On this page I list all of the posts from the Custom-Post-Type "work. Like this:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
'post_type' => 'work',
'post_status' => 'publish',
'posts_per_page' => 4,
'caller_get_posts'=> 1,
'paged'=> $paged
);
query_posts($args);
if( have_posts() ) {
while (have_posts()) : the_post(); ?>
<div class="workposts">
<div><a href="<?php the_permalink() ?>" title="<?php the_title() ?>" class="linked"><?php $image = get_post_meta($post->ID, "Image1", true); echo $image; ?></a></div>
<h3><a href="<?php the_permalink() ?>" title="<?php the_title() ?>" class="linked"><?php the_title() ?></a></h3>
<?php $subtitle = get_post_meta($post->ID, "Subtitle", true); echo $subtitle; ?>
</div>
<?php endwhile; } ?>
<div class="navigation">
<?php navi(); ?>
</div>
This works out very well so far. You can see it at: http://www.joeybottle.com/work/
Also the pagination is working here! NOW THE PROBLEM: When you click on a post you can watch it but the permalink is now with the "/casestudy"-Part. That's because of the "rewrite" line within the registration of the Custom-Post-Type. Here again:
</code>
Please especially check this line: 'rewrite' => array("slug" => "work/casestudy",'with_front'=>false),
When I change it to:
</code>
Please especially check this line: 'rewrite' => array("slug" => "work",'with_front'=>false),
And then update the permalinks the pagination on the "work"-Page does not work out any more. So for now I have to decide whether I like to have everything working but see the single-posts with the "/casestudy" part in the permalink or it's not working with the Pagination!
_______
To see the whole Problem please read also this post here from me: http://wpquestions.com/question/show/id/1397
That post shows almost the same problem, but that time with the pagination on a taxonomy-archive page. Maybe the two problems got the (almost) same solution.
_______
Thank you so much already! Hope that anybody could help me out! Goermez Wuff
rilwis answers:
When go to url: /work/page/2, WP will recognize this is a custom post type "work" with post name "page", and additional query var "page" with value "2". To make WP understand this is a page with name "work", I did as the following:
Add this code to functions.php file:
add_action('parse_query', 'rw_change_query');
function rw_change_query() {
global $wp_query;
if (empty($wp_query->query_vars['work']) || empty($wp_query->query_vars['page'])) return;
$rw_paged = $wp_query->query_vars['page'];
$rw_paged = intval(substr($rw_paged, 1));
//unset($wp_query->query_vars['page']);
unset($wp_query->query_vars['work']);
unset($wp_query->query_vars['post_type']);
unset($wp_query->query_vars['name']);
$wp_query->query_vars['post_type'] = 'page';
$wp_query->query_vars['pagename'] = 'work';
$wp_query->query_vars['paged'] = $rw_paged;
$wp_query->is_single = null;
$wp_query->is_page = 1;
}
I've tested with default TwentyTen navigation and it works. I don't know which navigation plugin you're using, but if it uses default WP variables, it should work, too.
Goermez Wuff comments:
Wow! Your code works and I am pretty excited that now I can show posts just with:
"www.joeybottle.com/work/custom_post_type-post/"
But now something else totally does not work any more :( The taxonomy "workcat" got some terms and normally you could see them like:
"www.joeybottle.com/work/custom_taxonomy-term/"
e.g. "www.joeybottle.com/work/design/"
But now that I've set that line we talked about to:
'rewrite' => array("slug" => "work",'with_front'=>false),
The taxonomy-slug.php seems to be not found bei WordPress... :/
Do you have any suggestions why this is now? If that last error wouldn't be there I would be sooooooo happy with your code!!! Hope you can help me a little more with this taxonomy-thing now.
Greatings!
rilwis comments:
That because you set rewrite rule for "workcat" exactly the same as "work" custom post type. I mean they use the same slug for rewrite rule.
This is a bad experience, for both developers and users. We cannot indicate that the url: www.joeybottle.com/work/design/ points to single post, or to taxonomies page with list of posts.
I suggest changing rewrite slug for "workcat" like this:
register_taxonomy( 'workcat', 'work', array( 'hierarchical' => true, 'label' => __('Work-Categories'), 'singular_label' => 'Work-Category', 'rewrite' => array('slug' => 'workcat'), 'query_var' => true) );
I see that you've done this already for "worktype", why not you do the same for "workcat"?
enodekciw answers:
Have you tried updating permalinks settings after changing that line to
'rewrite' => array("slug" => "work",'with_front'=>false),
?
If not - do that.
Settings -> Permalinks. And click update options ;)
Goermez Wuff comments:
Yes that's what I wrote. "And then update the permalinks..."
Or did I miss something here? The line you posted is exactly the same as mine, isn't it?