Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter peterorpete

    (@peterorpete)

    fixed, was a stupid error, called the taxonomy work instead of work_type. Works a treat now

    add_action( 'init', 'cptui_register_my_cpts' );
    function cptui_register_my_cpts() {
    	$labels = array(
    		"name" => "Case Studies",
    		"singular_name" => "Case Study",
    		);
    
    	$args = array(
    		"labels" => $labels,
    		"description" => "",
    		"public" => true,
    		"show_ui" => true,
    		"has_archive" => true,
    		"show_in_menu" => true,
    		"exclude_from_search" => false,
    		"capability_type" => "post",
    		"hierarchical" => false,
    		"rewrite" => array( "slug" => "%work_type%/case_studies", "with_front" => false ),
    		"query_var" => true,
    		"supports" => array( "title", "thumbnail", "page-attributes" ),
    		"taxonomies" => array( "work_type" )
    	);
    	register_post_type( "case_studies", $args );
    
    // End of cptui_register_my_cpts()
    }
    
    add_action( 'init', 'cptui_register_my_taxes' );
    function cptui_register_my_taxes() {
    
    	$labels = array(
    		"name" => "Work Type",
    		"label" => "Work Type",
    		);
    
    	$args = array(
    		"labels" => $labels,
    		"hierarchical" => true,
    		"label" => "Work Type",
    		"show_ui" => true,
    		"query_var" => true,
    		"rewrite" => array( 'slug' => 'work_type'),
    		"show_admin_column" => true,
    	);
    	register_taxonomy( "work_type", array( "testimonial", "case_studies" ), $args );
    
    	unset($labels);
    	unset($args);
    
    // End cptui_register_my_taxes
    }
    
    add_filter('post_type_link', 'work_types_permalink_structure', 10, 4);
    function work_types_permalink_structure($post_link, $post, $leavename, $sample) {
        if (false !== strpos($post_link, '%work_type%')) {
            $work_types_type_term = get_the_terms($post->ID, 'work_type');
            if (!empty($work_types_type_term))
                $post_link = str_replace('%work_type%', array_pop($work_types_type_term)->
                slug, $post_link);
            else
                $post_link = str_replace('%work_type%', 'uncategorized', $post_link);
        }
        return $post_link;
    }
    Thread Starter peterorpete

    (@peterorpete)

    hi still struggling on this, anybody got any ideas? Think i need to flush the permalinks, but i’m not sure how to get that working

    Thread Starter peterorpete

    (@peterorpete)

    Hi i have managed to get the permalink looking correct now. But when i click it it doesnt show the post. Does anyone have any advice?

    Here is the code so far:

    add_action( ‘init’, ‘cptui_register_my_cpts’ );
    function cptui_register_my_cpts() {

    post type
    $labels = array(
    “name” => “Case Studies”,
    “singular_name” => “Case Study”,
    );

    $args = array(
    “labels” => $labels,
    “description” => “”,
    “public” => true,
    “show_ui” => true,
    “has_archive” => false,
    “show_in_menu” => true,
    “exclude_from_search” => false,
    “capability_type” => “page”,
    “map_meta_cap” => true,
    “hierarchical” => false,
    “rewrite” => array( “slug” => “%work_type%/case-studies”, “with_front” => true ),
    “query_var” => true,

    “supports” => array( “title”, “thumbnail”, “page-attributes”, “post-formats” ),
    “taxonomies” => array( “work” )
    );
    register_post_type( “case_studies”, $args );

    // End of cptui_register_my_cpts()
    }

    taxonomy

    add_action( ‘init’, ‘cptui_register_my_taxes’ );
    function cptui_register_my_taxes() {

    $labels = array(
    “name” => “Work Type”,
    “label” => “Work Type”,
    );

    $args = array(
    “labels” => $labels,
    “hierarchical” => false,
    “label” => “Work Type”,
    “show_ui” => true,
    “query_var” => true,
    “rewrite” => array( ‘slug’ => ‘%work_type%’, ‘with_front’ => false ),
    “show_admin_column” => false,
    );
    register_taxonomy( “work”, array( “testimonial”, “case_studies” ), $args );

    // End cptui_register_my_taxes
    }

    function to change permalink structure

    add_filter(‘post_type_link’, ‘work_permalink_structure’, 10, 4);
    function work_permalink_structure($post_link, $post, $leavename, $sample)
    {
    if ( false !== strpos( $post_link, ‘%work_type%’ ) ) {
    $work_type_term = get_the_terms( $post->ID, ‘work’ );
    $post_link = str_replace( ‘%work_type%’, array_pop( $work_type_term )->slug, $post_link );
    }
    return $post_link;
    }

Viewing 3 replies - 1 through 3 (of 3 total)