Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

insert_model_entry does not set post_name if given title field value #606

Open
nickcernis opened this issue Jul 26, 2022 · 0 comments
Open
Labels
bug Something isn't working

Comments

@nickcernis
Copy link
Member

nickcernis commented Jul 26, 2022

When setting the value of a title field via insert_model_entry(), the post slug (post_name) is not set to use the slug-friendly unique version of the post title.

To reproduce

  1. Create a model called 'rabbit' with a title field named 'testTitle'.
  2. Run this code:
    $model_id   = 'rabbit';
    $title      = 'Petery';
    $field_data = [
  	  'testTitle'  => $title,						
    ];	

    $post_id = insert_model_entry( $model_id, $field_data );

    var_dump( $post_id );     
  1. Grab the post data for the new post ID via wp post get [id-of-post]
  2. The post_name value will be empty.

Expected behavior

post_name should be set to the unique slug-friendly version of the title, the same way it is if creating a post via the publisher admin.

Version information

  • Plugin version: 0.19.2
  • WordPress version: 6.0.1

Workaround

post_name can be set manually if needed:

	$model_id   = 'rabbit';
	$title      = 'Petery';
	$field_data = [
		'testTitle'  => $title,						
	];	

	$post_id = insert_model_entry( $model_id, $field_data );

	if ( ! is_wp_error( $post_id ) ) {		
		wp_update_post( [
			'ID' => $post_id,
			'post_name' => wp_unique_post_slug( sanitize_title( $title, 'save' ), $post_id, 'publish', $model_id, 0 ),
		] );
	}
	
	var_dump( $post_id );
@nickcernis nickcernis added the bug Something isn't working label Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant