• Resolved sixbids

    (@sixbids)


    I send posts to my site via e-mail and use an action on the save_post hook to parse a string from the body of the e-mail to set tags, custom fields and the featured image. That all works fine, but I’d like it also to select a single post template. I have created a new single post php file for the new single template and if I add a new post from the dashboard I can see it in the Post Attributes Template dropdown. But I haven’t figured out how to select it from my save_post hook.

    I thought the set_post_type function would do the trick, but not so. Here’s a snippet from my hook code. Here my template name is ‘Trail Post’.


    ...
    set_post_type($post_id, 'Trail Post');
    wp_set_post_tags($post_id, 'at', true);
    ...

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Set the meta value under key “_wp_page_template” to the template filename. I’m not 100% sure of the key name. “page” is used for pages of course, I’m not sure if that carries over to custom hierarchical post types. Solution: check to see what key name is used for a custom post where you manually selected the template. Use the phpMyAdmin app to directly examine DB content.

    Thread Starter sixbids

    (@sixbids)

    Excellent! That’s exactly what I was looking for. Thank You!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Setting post attributes template with php’ is closed to new replies.