WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
probleme with permalinks (1 post)

  1. skapiso
    Member
    Posted 1 year ago #

    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 :
    domain.com/film/filmname/scene/scenename.

    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() ) { 
    
    			$connected->the_post();
    			$title = $connected->post->post_name;
    
    			 wp_reset_postdata();
    		}
    		 wp_reset_postdata();
    
    		$taxonomy_slug = $title;
    
    	}else{
    		$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!!

    http://wordpress.org/extend/plugins/posts-to-posts/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags