I’ve been searching around for ever trying to fix this little bug of mine.
Basically i have a permalink structure of
/taxonomy/slug/ etc.
But paging doesn’t seem to work.
Here is my code.
<pre>
add_filter( ‘post_type_link’, ‘remove_parents_from_url’, 20, 4 );
function remove_parents_from_url( $post_link = ”, $post = ”, $leavename =”, $sample = ” ) {
$post_types = array(
‘news’,
‘test’,
‘article_new’
);
if ( !in_array( $post->post_type, $post_types ) )
return $post_link;
$uri = get_page_uri( $post->ID );
if ( false ) {
// not hierarchical slugs:
// site.com/test/{category}/{post}
$slug = array_pop( explode( ‘/’, $uri ) );
$post_link = str_replace( $uri, $slug, $post_link );
} else {
// for test hierarchical slugs:
// site.com/test/{category}/{post-parent}/{post}
$slug = $uri;
}
$category_in_url = get_post_meta( $post->ID, ‘category_in_url’, true );
if ( !$category_in_url ) {
if ( !$post->post_parent )
return $post_link;
$category_in_url = get_post_meta( $post->post_parent, ‘category_in_url’, true );
if ( !$category_in_url )
return $post_link;
}
// replace url on single admin post page in url editor
if ( preg_match( ‘/%(test|news)%/i’, $post_link, $matches ) )
$slug = $matches[0];
return str_replace( $slug, “{$category_in_url}/{$slug}”, $post_link );
}
function theme_filter_sample_permalink_html( $return, $id, $new_title, $new_slug ) {
$post = get_post( $id );
$post_types = array(
‘news’,
‘test’,
‘article_new’
);
if ( !in_array( $post->post_type, $post_types ) )
return $return;
$uri = get_page_uri( $post->ID );
$slugs = explode( ‘/’, $uri );
if ( 1 == count( $slugs ) )
return $return;
$slug = array_pop( $slugs );
$uri = implode( ‘/’, $slugs );
return str_replace( “{$uri}/”, ”, $return );
}
function theme_rewrite_rule() {
global $wp_rewrite;
// Warning! Ugly hack for rewrite old cateTory urls to cateGory
unset($wp_rewrite->extra_permastructs[‘category’]);
// category
add_rewrite_rule( ‘test/([^/]+)/([^/]+)/([^/]+)/?’, ‘index.php?test=$matches[3]’, ‘top’ );
add_rewrite_rule( ‘test/([^/]+)/([^/]+)/?’, ‘index.php?test=$matches[2]’, ‘top’ );
add_rewrite_rule( ‘nyheter/([^/]+)/([^/]+)/?’, ‘index.php?news=$matches[2]’, ‘top’ );
//$wp_rewrite->flush_rules();
}
add_action( ‘init’, ‘theme_rewrite_rule’, 1);
</pre>
Basically, I’m just trying to split a post into two pages using nextpage tag…
It works if I remove the rewrite but that I can’t do 🙂
Read more here:: Custom post type – SINGLE post pagination not working