Beiträge von Juri96

    Ok ich hab das jetzt mit dem Plugin "Custom Post Type Permalinks" gelöst. Ich mag zwar reine Code-Lösungen lieber, aber das übersteigt irgendwie meine Fähigkeiten momentan


    [size=12]Aber hier nochmal der ganze Code:[/SIZE]

    PHP
    /*===================================================================================*//*  Custom Post Type/*==================================================================================*/function add_post_type_profile() {// Set UI labels for Custom Post Type	$labels = array(		'name'                => _x( 'User Profiles', 'Post Type General Name', 'bresponZive' ),		'singular_name'       => _x( 'User Profile', 'Post Type Singular Name', 'bresponZive' ),		'menu_name'           => __( 'User Profiles', 'bresponZive' ),		'parent_item_colon'   => __( 'Parent User Profile', 'bresponZive' ),		'all_items'           => __( 'All User Profiles', 'bresponZive' ),		'view_item'           => __( 'View User Profile', 'bresponZive' ),		'add_new_item'        => __( 'Add New User Profile', 'bresponZive' ),		'add_new'             => __( 'Add New', 'bresponZive' ),		'edit_item'           => __( 'Edit User Profile', 'bresponZive' ),		'update_item'         => __( 'Update User Profile', 'bresponZive' ),		'search_items'        => __( 'Search User Profile', 'bresponZive' ),		'not_found'           => __( 'Not Found', 'bresponZive' ),		'not_found_in_trash'  => __( 'Not found in Trash', 'bresponZive' ),	);	// Set other options for Custom Post Type		$args = array(		'label'               => __( 'User Profiles', 'bresponZive' ),		'description'         => __( 'Movie news and reviews', 'bresponZive' ),		'labels'              => $labels,		// Features this CPT supports in Post Editor		'supports'            => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),		// You can associate this CPT with a taxonomy or custom taxonomy. 		'taxonomies'		  => array('post_tag'),		/* A hierarchical CPT is like Pages and can have		* Parent and child items. A non-hierarchical CPT		* is like Posts.		*/					'hierarchical'        => true,		'public'              => true,		'show_ui'             => true,		'show_in_menu'        => true,		'show_in_nav_menus'   => true,		'show_in_admin_bar'   => true,		'menu_position'       => 5,		'can_export'          => true,		'has_archive'         => true,		'exclude_from_search' => false,		'publicly_queryable'  => true,		'capability_type'     => 'post',	);		// Registering your Custom Post Type	register_post_type( 'profile', $args );}/* Hook into the 'init' action so that the function* Containing our post type registration is not * unnecessarily executed. */add_action( 'init', 'add_post_type_profile', 0 );function add_post_type_article() {// Set UI labels for Custom Post Type	$labels = array(		'name'                => _x( 'Articles', 'Post Type General Name', 'bresponZive' ),		'singular_name'       => _x( 'Article', 'Post Type Singular Name', 'bresponZive' ),		'menu_name'           => __( 'Articles', 'bresponZive' ),		'parent_item_colon'   => __( 'Parent Article', 'bresponZive' ),		'all_items'           => __( 'All Articles', 'bresponZive' ),		'view_item'           => __( 'View Article', 'bresponZive' ),		'add_new_item'        => __( 'Add New Article', 'bresponZive' ),		'add_new'             => __( 'Add New', 'bresponZive' ),		'edit_item'           => __( 'Edit Article', 'bresponZive' ),		'update_item'         => __( 'Update Article', 'bresponZive' ),		'search_items'        => __( 'Search Article', 'bresponZive' ),		'not_found'           => __( 'Not Found', 'bresponZive' ),		'not_found_in_trash'  => __( 'Not found in Trash', 'bresponZive' ),	);	// Set other options for Custom Post Type		$args = array(		'label'               => __( 'Articles', 'bresponZive' ),		'description'         => __( 'Movie news and reviews', 'bresponZive' ),		'labels'              => $labels,		// Features this CPT supports in Post Editor		'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),		// You can associate this CPT with a taxonomy or custom taxonomy. 		'taxonomies'		  => array('post_tag'),		/* A hierarchical CPT is like Pages and can have		* Parent and child items. A non-hierarchical CPT		* is like Posts.		*/					'hierarchical'        => true,		'public'              => true,		'show_ui'             => true,		'show_in_menu'        => true,		'show_in_nav_menus'   => true,		'show_in_admin_bar'   => true,		'menu_position'       => 5,		'can_export'          => true,		'has_archive'         => true,		'exclude_from_search' => false,		'publicly_queryable'  => true,		'capability_type'     => 'post',	);		// Registering your Custom Post Type	register_post_type( 'article', $args );}/* Hook into the 'init' action so that the function* Containing our post type registration is not * unnecessarily executed. */add_action( 'init', 'add_post_type_article', 0 );
    PHP
    /*===================================================================================*//*  Custom Permalink/*==================================================================================*/	function article_rewrite() {    global $wp_rewrite;    $queryarg = 'post_type=article&p=';    $wp_rewrite->add_rewrite_tag( '%cpt_id%'	, '([^/]+)', $queryarg );	$wp_rewrite->add_rewrite_tag( '%cpt_type%'	, '([^/]+)', $queryarg );	$wp_rewrite->add_rewrite_tag( '%cpt_title%'	, '([^/]+)', $queryarg );     $wp_rewrite->add_permastruct( 'article'   	, '/%cpt_type%/%cpt_title%-id=%cpt_id%', false );		}add_action( 'init', 'article_rewrite' );function custom_article_permalink( $post_link, $id = 0, $leavename ) {    global $wp_rewrite;    $post 		= get_post( $id );	$uni_id 	= get_post_meta( $post->ID, 'unique_post_identifier', true);	$post_type 	= get_post_type( $post->ID );	$post_title = sanitize_title( get_the_title( $post->ID ));       if ( is_wp_error( $post ) )        return $post;        $newlink = $wp_rewrite->get_extra_permastruct( 'article' );		$newlink = str_replace( '%cpt_id%', $post->ID, $newlink );		$newlink = str_replace( '%cpt_title%', $post_title, $newlink );		$newlink = str_replace( '%cpt_type%', $post_type, $newlink );        $newlink = home_url( user_trailingslashit( $newlink ) );		    return $newlink;	}add_filter('post_type_link', 'custom_article_permalink', 1, 3);


    Hallo erstmal,

    ich habe ein kleines Problem: Ich habe zwei Funktionen, mit denen ich im Stande bin die URL einer CPT zu ändern - ich krieg's allerdings nicht hin das so anzupassen, dass es mit mehrere CPTs funktioniert. Was ich schon probiert habe:


    1. Die Funktionen zu kopieren und umzubenennen - geht nicht, da die letzte immer die obere überschreibt (gleicher Filter :confused:)
    2. add_rewrite_tag akzeptiert auch nur einen String



    Diese Funktion gefällt mir eig. so ganz gut nur das wär der letzte Schliff, wenn ihr versteht;-). Ich würde sehr über etwas Hilfe freuen :)