Skip to main content
added 294 characters in body
Source Link

I have a fairly complicated site structure and cannot seem to get the URL structure to work correctly, including pagination. This is mainly to cope with loading articles assigned to a specific custom post type, which may all be nested.

My (cut down) register post types:

register_post_type('continent',
    array(
        'rewrite' => array('slug' => 'moving-to'),
    )
);

register_post_type('country',
    array(
        'rewrite' => array('slug' => 'moving-to/%continent%'),
    )
);

So I have a category moving-to, a custom post type continent and a custom post type country.

/moving-to/

/moving-to/continent

/moving-to/continent/country

These first three display posts from the category, posts assigned to the continent and posts assigned to the country. I cannot get pagination to work with them as I think the /continent/country is interfering with the /page/n pagination.

/moving-to/page/2 - Works OK

/moving-to/continent/page/2 - Tries to load unknown country "page"

/moving-to/continent/country/page/2 - Strips page/2 from the URL

I assume I need to exclude any country of "page" from the rewrite, or to just not have a nested continent in the url.

Part two is being able to have a category after each continent or country

/moving-to/continent/category-name

/moving-to/continent/country/category-name

Again with pagination

/moving-to/continent/category-name/page/2

/moving-to/continent/country/category-name/page/2

/moving-to/continent/country

I realise this all sounds a bit specific (borderline off-topic) but it all boils down toI'm basically asking how to add rewrite rule(s) to cope with nested post types and still have pagination working.enable the following URL structures:

/moving-to/
/moving-to/continent/
/moving-to/continent/country
/moving-to/page/2
/moving-to/continent/page/2
/moving-to/continent/country/page/2
/moving-to/continent/category
/moving-to/continent/country/category
/moving-to/continent/category/page/2
/moving-to/continent/country/category/page/2

I have a fairly complicated site structure and cannot seem to get the URL structure to work correctly, including pagination. This is mainly to cope with loading articles assigned to a specific custom post type, which may all be nested.

My (cut down) register post types:

register_post_type('continent',
    array(
        'rewrite' => array('slug' => 'moving-to'),
    )
);

register_post_type('country',
    array(
        'rewrite' => array('slug' => 'moving-to/%continent%'),
    )
);

So I have a category moving-to, a custom post type continent and a custom post type country.

/moving-to/

/moving-to/continent

/moving-to/continent/country

These first three display posts from the category, posts assigned to the continent and posts assigned to the country. I cannot get pagination to work with them as I think the /continent/country is interfering with the /page/n pagination.

/moving-to/page/2 - Works OK

/moving-to/continent/page/2 - Tries to load unknown country "page"

/moving-to/continent/country/page/2 - Strips page/2 from the URL

I assume I need to exclude any country of "page" from the rewrite, or to just not have a nested continent in the url.

Part two is being able to have a category after each continent or country

/moving-to/continent/category-name

/moving-to/continent/country/category-name

Again with pagination

/moving-to/continent/category-name/page/2

/moving-to/continent/country/category-name/page/2

/moving-to/continent/country

I realise this all sounds a bit specific (borderline off-topic) but it all boils down to how to add rewrite rule(s) to cope with nested post types and still have pagination working.

I have a fairly complicated site structure and cannot seem to get the URL structure to work correctly, including pagination. This is mainly to cope with loading articles assigned to a specific custom post type, which may all be nested.

My (cut down) register post types:

register_post_type('continent',
    array(
        'rewrite' => array('slug' => 'moving-to'),
    )
);

register_post_type('country',
    array(
        'rewrite' => array('slug' => 'moving-to/%continent%'),
    )
);

So I have a category moving-to, a custom post type continent and a custom post type country.

/moving-to/

/moving-to/continent

/moving-to/continent/country

These first three display posts from the category, posts assigned to the continent and posts assigned to the country. I cannot get pagination to work with them as I think the /continent/country is interfering with the /page/n pagination.

/moving-to/page/2 - Works OK

/moving-to/continent/page/2 - Tries to load unknown country "page"

/moving-to/continent/country/page/2 - Strips page/2 from the URL

I assume I need to exclude any country of "page" from the rewrite, or to just not have a nested continent in the url.

Part two is being able to have a category after each continent or country

/moving-to/continent/category-name

/moving-to/continent/country/category-name

Again with pagination

/moving-to/continent/category-name/page/2

/moving-to/continent/country/category-name/page/2

/moving-to/continent/country

I realise this all sounds a bit specific (borderline off-topic) I'm basically asking how to enable the following URL structures:

/moving-to/
/moving-to/continent/
/moving-to/continent/country
/moving-to/page/2
/moving-to/continent/page/2
/moving-to/continent/country/page/2
/moving-to/continent/category
/moving-to/continent/country/category
/moving-to/continent/category/page/2
/moving-to/continent/country/category/page/2
Source Link

Wordpress Rewrite rule for nested post types

I have a fairly complicated site structure and cannot seem to get the URL structure to work correctly, including pagination. This is mainly to cope with loading articles assigned to a specific custom post type, which may all be nested.

My (cut down) register post types:

register_post_type('continent',
    array(
        'rewrite' => array('slug' => 'moving-to'),
    )
);

register_post_type('country',
    array(
        'rewrite' => array('slug' => 'moving-to/%continent%'),
    )
);

So I have a category moving-to, a custom post type continent and a custom post type country.

/moving-to/

/moving-to/continent

/moving-to/continent/country

These first three display posts from the category, posts assigned to the continent and posts assigned to the country. I cannot get pagination to work with them as I think the /continent/country is interfering with the /page/n pagination.

/moving-to/page/2 - Works OK

/moving-to/continent/page/2 - Tries to load unknown country "page"

/moving-to/continent/country/page/2 - Strips page/2 from the URL

I assume I need to exclude any country of "page" from the rewrite, or to just not have a nested continent in the url.

Part two is being able to have a category after each continent or country

/moving-to/continent/category-name

/moving-to/continent/country/category-name

Again with pagination

/moving-to/continent/category-name/page/2

/moving-to/continent/country/category-name/page/2

/moving-to/continent/country

I realise this all sounds a bit specific (borderline off-topic) but it all boils down to how to add rewrite rule(s) to cope with nested post types and still have pagination working.