Hi there,
I closed the previous ticket in error: https://toolset.com/forums/topic/function-to-assign-content-template-from-api-import/
This is still not working to assign a views template on import / post creation:
function save_book_meta( $post_id, $post, $update ) {
$post_type = get_post_type($post_id);
// If this isn't a 'book' post, don't update it.
if ( "used-boat" != $post_type ) return;
// - Update the post's metadata.
update_post_meta( $post_id, '_views_template', 1111 );
}
add_action( 'save_post', 'save_book_meta', 10, 3 );
Could this be because it's operating too late for the action to work? I am using All Import plugin.
Thanks
Hi, if you create a used-boat post manually in wp-admin, is the correct Content Template assigned by this code? To test it, first be sure to check to see if any Content Template is assigned to Used Boats by default. If there is one, unassign it temporarily. Then create a new post and check to see if the correct CT is assigned.
Let me know what you find out.
Hi there,
I managed to solve it by adding the correct number of view template to a generic field in the post types in the actual import - see attachment.
Thanks for the initial help.
Paul