• I’ve my custom posts types and polylang works great with them.

    But, trying to speed up the inserting process, when I post a new post, I don’t need to write the name, because it is automatically get by combining 2 metas.
    Here is the script I use (no credit for me, I got it from another forum)

    
    <?php function title_from_meta( $data , $postarr ) {
    
        // We only care if it's my type
        if( $data[ 'post_type' ] === 'mytype' ) {
    
            // get name from _POST or from post_meta
            $mytitle = ( ! empty( $_POST[ 'meta1' ] ) && ! empty( $_POST[ 'meta2' ] )  ) 
    						? $_POST[ 'meta1' ] . $_POST[ 'meta2' ] 
    						: get_post_meta( $postarr[ 'ID' ], 'meta1', true ) . get_post_meta( $postarr[ 'ID' ], 'meta2', true );
    
            // if the name is not empty, we want to set the title
            if( $mytitle !== '' ) {
    
                // sanitize name for title
                $data[ 'post_title' ] = $mytitle;
                // sanitize the name for the slug
                $data[ 'post_name' ]  = sanitize_title( sanitize_title_with_dashes( $mytitle, '', 'save' ) );
            }
        }
        return $data;
    }
    add_filter( 'wp_insert_post_data' , 'title_from_meta' , '99', 2 );
    ?>

    PROBLEM:
    When I click on post, I get the right permalinks:
    https://mysite.com/en/my-post-type-slug/postname
    https://mysite.com/fr/my-post-type-slug/postname-2

    (where post name = meta1meta2)

    but, if I try to access those addresses wordpress finds nothing and the links to the other language doen’t work…

    I did try to deactivate or reactivate the plugins, resave the permalinks structure, but nothing works. Works only if I comment out that piece of code… any Ideas? Thanks!!

  • The topic ‘Confilct with ‘wp_insert_post_data’ and post name’ is closed to new replies.