I think it’s generally better to include the CMB2 plugin. As far as your question, there are a lot of ways to go about this, but I think your way is a solid one. I would make a couple changes. I’d update your option values to be the name of your template-parts:
'options' => array(
'single-video' => 'Single Video',
),
Then I would add a helper function to your theme’s functions.php:
function idver_get_post_template_part( $post_id ) {
$template = get_post_meta( $post_id, 'temp_ver', 1 );
if ( ! $template ) {
$template="default"; // Whatever your fallback template part is
}
get_template_part( $template );
}
(obviously, update ‘default’ to whatever your default/fallback template part should be. If NO default, that helper function should be updated a bit)
Then in your single.php, just call:
idver_get_post_template_part( get_the_ID() );
Related Posts:
- Add custom meta box on Post page
- Let author add field to metabox by pressing a button
- WordPress 3.1.2 Bug: add_theme_support() and video post format registering twice
- Adding a drop-down (select tag) option under Menu Settings in WordPress Admin
- Check for and enforce unique value in user-entered custom meta field in WP Admin
- Adding another state (spam, reject, approve) to wordpress comments?
- echo value from ‘select’ field type into page template using cmb2?
- How to remove Profile Picture section or the message “You can change your profile picture on Gravatar.”
- Post format selector in Thematic child theme post class
- Add field to posts (checkbox) that only one post can have
- generate unique number when registering a user
- Problem in custom meta boxes
- Multiplile values checkbox or select in custom meta box
- Allow Users to Set Password During Registration
- Custom protected password page with ACF
- Add URL field to the link post format
- How WordPress autosave can save plugin fields?
- How can I filter the contents of a metafield before it’s displayed in the admin?
- Add ‘Right Now’ widget to custom dashboard
- Passing page url into a custom field via the Press-This bookmarklet
- How to extend nav-menu-item-control data in Appearance > Customize?
- Custom column sorting in WordPress admin post table
- How to get multiple Action Hooks in an Array
- woocommerce Add custom field set like billing fields
- Creating Search Engine Friendly URL’s with Word Press
- FacetWP group listings by custom field [closed]
- Custom Field Template seriously messed up in WP 3.1.1
- Make wordpress generate a custom XML file(not a sitemap) that is updated only when new content is posted?
- Advanced Custom Fields: Sorting custom columns with custom fields sorts only by date
- Custom Taxonomy to dropdown box on adminside wordpress
- The Best Way to always load the newest version of 3rd party code
- Better Method for Multiple Meta Boxes
- Why do posts disappear from admin after upgrading from WP 2.7.1 to 3.0.1?
- How to change popular term checklist title when edit post?
- Add a date updated/date modified option using custom fields
- How to add textarea field to taxonomy (tag)?
- How to add an extra button on woocommerce shop page and use it to send the product info with image in a mail? [closed]
- Woocomerce custom billing address fields display in order details [closed]
- custom meta box for page default template
- Cannot save CPT meta box
- How to get Related Custom Posts?
- I need a “Choose from existing content” popin
- Qtranslate + Woocommerce (multiple tinymce) [closed]
- Changing settings of WooCommerce
- Redirect to another page using contact form 7? [closed]
- What requirements for ACF custom fields key and name properties?
- Toggle custom fields?
- Woocommerce – Print Product’s Custom Field In Email
- How can I hide custom field from users used for caching response from external api?
- Get users based on month ACF datepicker field
- What is the best way to modify Admin Panel on WordPress?
- how to make a custom field readonly or disabled by user role?
- theme customizer – can a single option pass multiple values?
- MetaBox not saving after empty
- Make tag archive display post are ordered by post format
- How can I modify a custom post type and custom page template for a child theme if all content seams to be handled by theme’s ‘native’ plugin?
- How to auto add nofollow to links in custom field?
- How Can I limit the visible part of the short-description on the Category page?
- WooCommer Product Category Loop – How to change the display order of the rating and price?
- Showing Meta Box via Jquery Checkbox
- How to Render Post Types in RSS Feed?
- problem saving/ retrieving custom meta with wp alchemy metabox
- Meta Box Plugin Cloned Fields – Multiple Foreach values
- Make separate text boxes for separate WordPress Custom Fields
- Is it possible to add custom badges to product attributes conditionally, based on custom field?
- How to get Previous Visited Page Information
- WordPress category custom title
- No plugin populate user information in to form
- How can Use custom input field in functions.php page?
- Multiple header style under meta box
- Use a custom page with dynamic content as a user profile page
- Query Product categories what have a custom field
- Adding an option to post editor to show a site disclaimer or message
- How to pass multiple custom fields as shortcode’s parameters
- Change meta-box title- “LearnDash Quiz Settings” to “Quiz Settings”
- Embedded Options in a Custom Metabox
- Simple Data picker meta box
- Remove Custom metabox from particular page template is used
- Replace publish date in blog module with custom field
- Creating Nested custom fields
- How to add custom Author Info Box to blog posts “only” and NOT custom post templates
- How to add H1 Tag on Homepage?
- Do something with thumbnail image on post publish
- issue with saving custom metaboxes fields
- after checked the checkbox in backend, dont show social link on frontend
- How to display all custom fields associated with a post type – IN THE ADMIN AREA?
- Add commentmeta custom field to every published comment with SQL
- Does WordPress support template resources/custom fields
- When post is updated, custom metadata in text area field is overwritten
- How to make my wordpress site responds for 2 domains
- Where can I find the code for the menu page meta boxes?
- How can i do custom author list?
- Need Advice to Working with Custom Post Meta
- Extending a CPT by Created by another plugin
- Custom Slider Per Page created
- Need help saving input fields for Security Deposit plugin in WC Vendors page
- How I can change PayPal IPN ‘custom’ field in woocommerce?
- Consolidate ‘add-to-cart’ buttons into one ‘add-all-to-cart’ button
- How to change data format in custom meta box field [closed]
- Add custom information in editor summary