Problem: I would like to programmatically assign a Content Template to imported posts.
Solution: Content Template assignment is defined by a hidden custom field "_views_template" that holds the ID of the Content Template to apply to a given post. You can use the save_post hook to apply this value automatically whenever a post is saved:
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 ( "book" != $post_type ) return; // - Update the post's metadata. update_post_meta( $post_id, '_views_template', 12345 ); } add_action( 'save_post', 'save_book_meta', 10, 3 );
Relevant Documentation:
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
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 3 replies, has 2 voices.
Last updated by 6 years, 5 months ago.
Assisted by: Christian Cox.