I fixed this issue by adding a rewrite rule to my functions.php file at the top:
function melon_rewrites($rules) {
$new_rules = array(
'parties/([^/]*)/([^/]*)$' => 'index.php?melon-parties=$matches[2]'
);
$rules = $new_rules + $rules;
return $rules;
}
add_filter('rewrite_rules_array', 'melon_rewrites');
I then changed my cpt to allow a query_var:
function register_custom_post_types() {
$args = array(
'labels' => array(
'name' => __( 'Parties' ),
'singular_name' => __( 'Party' )
),
'menu_position' => 50,
'public' => true,
'has_archive' => 'true',
'hierarchical' => true,
'taxonomies' => array('party-tags'),
'capability_type' => 'post',
'query_var' => true,
'rewrite' => false,
'supports' => array('title', 'editor', 'thumbnail', 'revisions', 'page-attributes')
);
register_post_type('melon-parties', $args);
$args = array(
'labels' => array(
'name' => __( 'Type of Parties' ),
'singular_name' => __( 'Type of Party' )
),
'menu_position' => 50,
'public' => true,
'has_archive' => 'true',
'hierarchical' => true,
'show_ui' => true,
'publicly_queryable' => true,
'capability_type' => 'page',
'query_var' => true,
'supports' => array('title', 'thumbnail', 'revisions', 'page-attributes'),
'rewrite' => false
);
register_post_type('party-categories', $args);
$args = array(
'labels' => array(
'name' => __( 'Home Slider' ),
'singular_name' => __( 'Home Slide' )
),
'menu_position' => 50,
'public' => false,
'show_ui' => true,
'hierarchical' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'supports' => array('title', 'editor', 'thumbnail', 'revisions', 'page-attributes')
);
register_post_type('melon-home-slider', $args);
$args = array(
'labels' => array(
'name' => __( 'Case Studies' ),
'singular_name' => __( 'Case Study' )
),
'menu_position' => 50,
'public' => true,
'hierarchical' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'rewrite' => array('with_front' => false, 'slug' => 'case-studies'),
'supports' => array('title', 'editor', 'thumbnail', 'revisions', 'page-attributes')
);
register_post_type('melon-case-studies', $args);
}
add_action( 'init', 'register_custom_post_types' );
I also had to make a couple changes to my rewrite rules as i wasnt actually pointing to my cpt:
add_action('init', 'tdd_add_rewrite_rules');
function tdd_add_rewrite_rules() {
// Register custom rewrite rules
add_rewrite_tag('%melon-parties%', '([^/]+)');
add_rewrite_tag('%party-categories%', '([^/]+)');
add_permastruct('melon-parties', 'parties/%party-categories%/%melon-parties%', false);
}
add_filter('post_type_link', 'tdd_permalinks', 10, 3);
function tdd_permalinks($permalink, $post, $leavename) {
$no_data="no-category";
$post_id = $post->ID;
if($post->post_type != 'melon-parties' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft')))
return $permalink;
$var1 = get_post_meta($post_id, 'cmb-event_category', true);
$var1 = get_the_title($var1);
$var1 = sanitize_title($var1);
if(!$var1) { $var1 = $no_data; }
$permalink = str_replace('%party-categories%', $var1, $permalink);
return $permalink;
}
add_action('init', 'partyCategoryRewriteRules');
function partyCategoryRewriteRules() {
// Register custom rewrite rules
global $wp_rewrite;
$wp_rewrite->add_rewrite_tag('%party-categories%', '([^/]+)', 'party-categories=");
$wp_rewrite->add_permastruct("party-categories', '/parties/%party-categories%', false);
}
add_filter('post_type_link', 'partyCategoryPermalinks', 10, 3);
function partyCategoryPermalinks($permalink, $post, $leavename) {
$no_data="no-category";
$post_id = $post->ID;
if($post->post_type != 'party-categories' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft')))
return $permalink;
$var1 = $post->post_name;
$var1 = sanitize_title($var1);
if(!$var1) { $var1 = $no_data; }
$permalink = str_replace('%party-categories%', $var1, $permalink);
return $permalink;
}
Now my url structure is correct