Skip Navigation

[Resolved] PHP Function to assign Views Template

This support ticket is created 6 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by Paul 6 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#950228

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

#950497

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.

#951304
Screenshot(52).png

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