Support » Plugin: Posts 2 Posts » probleme with permalinks

  • Hi everybody.
    I’m trying something since few days but it still not working.

    I have 2 custom post: film and scene
    I have created a relation between them.

    What i want to do is change the permalink for a scene in order to have :

    What i have done works a little but on a single scene page, where I call several other function for display related post of “scene” type, It seems that my function modify all the permalinks of the “scene” parmalinks on the page, like if they have all the same post id…

    The code I use :

    add_filter('post_type_link', 'scene_permalink', 10, 3);
    function scene_permalink($permalink, $post_id, $leavename) {
    if ( is_singular( 'scene' ) && ! is_admin() ) {
        if (strpos($permalink, '%scenetags%') === FALSE) return $permalink;
        // Get post
        $post = get_post($post_id);
        if (!$post) return $permalink;
    	////////// AFFICHAGE DU FILM
    	$connected = new WP_Query( array(
    	  'connected_type' => 'film2scene',
    	  'connected_items' => $post_id->ID
    	) );
    	if ( $connected->have_posts() ) {
    		while ( $connected->have_posts() ) { 
    			$title = $connected->post->post_name;
    		$taxonomy_slug = $title;
    		$taxonomy_slug = 'inconnu';
        return str_replace('%scenetags%', $taxonomy_slug, $permalink);
    } }

    I’m not sure but it is like if the ” wp_reset_postdata();” didn’t work correctly.. or the filter of my function is too general?

    Thank you for your help!!

  • The topic ‘probleme with permalinks’ is closed to new replies.