I would like to achive the following link structure on my site:
- /properties/ -> a
properties
page withproperties
CPT, page 1. - /properties/page/2 -> a
properties
page withproperties
CPT, page 2. - /properties/property-name -> a single
properties
page with a property details.
I have a Custom Post Type (CPT) called property
. It’s registered as following with the rewrite
rule specified as 'rewrite' => array('slug' => 'properties', 'with_front' => false)
:
function property_post_type_init() {
$labels = array(
'name' => _x('Properties', 'post type general name'),
'singular_name' => _x('Property', 'post type singular name'),
'add_new' => _x('Add New', 'property')
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'rewrite' => array('slug' => 'properties', 'with_front' => false),
'query_var' => true,
'capability_type' => 'post',
'hierarchical' => false,
'show_in_nav_menus' => false,
'menu_position' => 5,
'supports' => array(
'title',
'editor',
'revisions'
)
);
register_post_type('property',$args);
I also have a page with the slug properties
and the permalink structure is set as /%category%/%postname%/
On the Properties
page I construct a new WP_Query
object with the following arguments:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'property',
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged
);
return $args;
I use a custom pagination code (in functions.php) which generates pagination correctly with the correct urls:
<my-site>/properties/
<my-site>/properties/page/2/
<my-site>/properties/page/3/
However, when I click on any page in the pagination I get redirected to 404 page. I’ve expected the query params and they are the following:
[page] => 2
[property] => page
[post_type] => property
[name] => page
Which is not correct! I don’t understand where these parameters are coming from:
[page] => 2
[property] => page
[name] => page
I’m sure it’s something to do with the rewrite
rule when registering a CPT.
How can I achive the following set up to work correctly:
- A
properties
page that displays allproperties
custom post types posts with pagination. - A
properties
custom post type with'rewrite' => array('slug' => 'properties', 'with_front' => false)
rule. - Permalink of
/%category%/%postname%/
structure
So that I have the following link structure:
- /properties/ -> a
properties
page withproperties
CPT, page 1. - /properties/page/2 -> a
properties
page withproperties
CPT, page 2. - /properties/property-name -> a single
properties
page with a property details.
Hope that makes sense.
Thanks,
Dasha