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 here: https://wordpress.stackexchange.com/questions/94364/set-post-title-from-two-meta-fields)
<?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: http://example.com/en/my-post-type-slug/postname http://example.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!!