Hello,
I have 2 taxonomy "country" and "theme" inside a post type "products" :
Inside country, hierarchical taxonomy, i have (Africa, Europe etc...).
Inside theme, also hierarchical taxonomy, i have (Hotels, Circuits etc...)
So my post type structure is like :
post_type ====> produits
|
taxonomies ==> |__destinations -----------------------types
|__ France |__ Hotels
terms ===> |__ Afrique-du-sud etc... |__ Circuits etc...
I have workings url likes :
mywebsite.com/products(optionnal)/country/Europe/theme/Hotels
mywebsite.com/products(optionnal)/country/Europe
To get these url's working i followed [[LINK href="http://thereforei.am/2011/10/28/advanced-taxonomy-queries-with-pretty-urls/"]][[/LINK]] tutorial
So inside my functions.php i have :
function eg_add_rewrite_rules() {
global $wp_rewrite;
$new_rules = array(
'produits/(destinations|types)/(.+?)/(destinations|types)/(.+?)/?$' => 'index.php?post_type=produits&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2) . '&' . $wp_rewrite->preg_index(3) . '=' . $wp_rewrite->preg_index(4),
'produits/(destinations|types)/(.+)/?$' => 'index.php?post_type=produits&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2)
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action( 'generate_rewrite_rules', 'eg_add_rewrite_rules' );
Now i create pagination with wp_pagnavi, the pagination is displayed, but when i try to access
mywebsite.com/products(optionnal)/country/Europe/theme/Hotels/page/2/
or
mywebsite.com/products(optionnal)/country/Europe/theme/Hotels/paged/2/
I always got 404 error (PS: the pagination works well for others sections "eg: my blog" of the site).
For information i use custom archive template called : archive-products.php as the tutorial said.
I searched, asked questions on many forums, without success.
Here is my last hope, could you help me please?
Thank you.
Hariprasad Vijayan answers:
Hello,
Is your .htaccess is updated? If not, go to Permalinks sections from WordPress dashboard and update permalinks. Then try to access the url.
Hariprasad Vijayan comments:
Still have error change eg_add_rewrite_rules() with following code.
function eg_add_rewrite_rules() {
global $wp_rewrite;
$new_rules = array(
'products/(country|theme)/(.+?)/(country|theme)/(.+?)/?$' => 'index.php?post_type=products&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2) . '&' . $wp_rewrite->preg_index(3) . '=' . $wp_rewrite->preg_index(4),
'products/(country|theme)/(.+)/?$' => 'index.php?post_type=products&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2)
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
$wp_rewrite->flush_rules( false );
}
add_action( 'generate_rewrite_rules', 'eg_add_rewrite_rules' );
ngita comments:
Hello,
I did it many times but no success, i can send you as P.M the website url?
ngita comments:
Hello,
I did it many times but no success, i can send you as P.M the website url?
ngita comments:
I got blank page inside admin page and fron-end page, may be because of the : $wp_rewrite->flush_rules( false );
your implemented?
ngita comments:
my pagination code :
/// Pagination
if( !function_exists( 'theme_pagination' ) ) {
function theme_pagination($kery) {
global $wp_query, $wp_rewrite;
$wp_query->query_vars['paged'] > 1 ? $current = $wp_query->query_vars['paged'] : $current = 1;
$pagination = array(
'base' => @add_query_arg('paged','%#%'),
'format' => '',
'total' => $wp_query->max_num_pages,
'current' => $current,
'show_all' => false,
'end_size' => 1,
'mid_size' => 2,
'type' => 'list',
'next_text' => '»',
'prev_text' => '«'
);
if( $wp_rewrite->using_permalinks() )
$pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'paged/%#%/', 'paged' );
if( !empty($wp_query->query_vars['s']) )
$pagination['add_args'] = array( 's' => str_replace( ' ' , '+', get_query_var( 's' ) ) );
echo str_replace('paged/1/','', paginate_links( $pagination ) );
}
}
my loop code :
ngita comments:
and this is the urls:
www.coins-voyages(dot)com/produits/destinations/france/
when you go to the /page/2 which gives : www.coins-voyages(dot)com/produits/destinations/france/paged/2
it returns 404 error page
Hariprasad Vijayan comments:
Try following code in function.php
function remove_page_from_query_string($query_string)
{
if ($query_string['name'] == 'page' && isset($query_string['page'])) {
unset($query_string['name']);
// 'page' in the query_string looks like '/2', so i'm spliting it out
list($delim, $page_index) = split('/', $query_string['page']);
$query_string['paged'] = $page_index;
}
return $query_string;
}
add_filter('request', 'remove_page_from_query_string');
function fix_category_pagination($qs){
if(isset($qs['category_name']) && isset($qs['paged'])){
$qs['post_type'] = get_post_types($args = array(
'public' => true,
'_builtin' => false
));
array_push($qs['post_type'],'post');
}
return $qs;
}
add_filter('request', 'fix_category_pagination');
ngita comments:
Hello,
Thank you, i put $query string ou $query_string?
Hariprasad Vijayan comments:
Is it working?
ngita comments:
No, it's not,
ngita comments:
When i deactivate permalink followings urls works very well :
mywebiste.com/?post_type=produits&destinations=france&types=hotels&paged=2
mywebiste.com/?post_type=produits&destinations=france&paged=2
mywebiste.com/?post_type=produits&paged=2
but as i show above i rewrite those queries in my functions.php as :
function eg_add_rewrite_rules() {
global $wp_rewrite;
$new_rules = array(
'produits/(destinations|types)/(.+?)/(destinations|types)/(.+?)/?$' => 'index.php?post_type=produits&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2) . '&' . $wp_rewrite->preg_index(3) . '=' . $wp_rewrite->preg_index(4),
'produits/(destinations|types)/(.+)/?$' => 'index.php?post_type=produits&' . $wp_rewrite->preg_index(1) . '=' . $wp_rewrite->preg_index(2)
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
// $wp_rewrite->flush_rules( false );
}
add_action( 'generate_rewrite_rules', 'eg_add_rewrite_rules' );
So i guess it because of this rewrite rule? how do you think?