0

I have a custom post type services;

register_post_type( 'services', array( 
            'label' => 'Services',  
            'public' => true, 
            'supports' => array( 'title', 'editor','comments'),
            'rewrite'=>array('slug'=>'services'),
            'public' => true, 
                'capability_type' => 'post',
                'hierarchical' => false,
            'has_archive'=>true
            ) ); 

I added a metabox to get country data. And im showing the posts;

$current_page = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$country=get_query_var('country');
global $wp_query;
$wp_query = null;
$wp_query = new WP_Query( "
    post_type=services&
    meta_key=country&
    meta_value=$country
    &order=ASC&
    posts_per_page=5&
    paged=$current_page" );

Also i added this to my functions.php

function add_query_vars( $query_vars ) {
  $query_vars[] = 'country';
  return $query_vars;
}
add_filter( 'query_vars', 'add_query_vars' );
add_rewrite_rule(
    '^services/district-([^/]*)/?',
    'index.php?post_type=services&country=$matches[1]','top');  

http://www.domain.com/services/fr-district
So; its working very well. But my problem is pagination. I tried to add this;

add_rewrite_rule(
        '^services/district-([^/]*)/page/([^/]*)?',
        'index.php?post_type=services&country=$matches[1]&paged=$matches[2]','top');  

But still, its not working http://www.domain.com/services/fr-district/page/2 it is giving me 404 error.

Ajna Sarut
  • 19
  • 5
  • I think use country is custom taxonomy instead of custom meta box. So you can use wordpress default taxonomy page instead going to this much complicated... – Datta Parad May 23 '14 at 07:09
  • Country was an example, i need to use metadata. Also; I solved that issue. I think its not the correct way but its working at the end. I added anothher var $query_vars[] = 'pagetmp'; and i collected the page number as pagetmp=$matches[2] New url is like http://www.domain.com/services/fr-district/2 (not fr-district/page/2 i cant use page tag, it is the problem). I changed my pagination structure totally and its working. – Ajna Sarut May 23 '14 at 07:23

0 Answers0