You haven’t quite got a grip on the switch
statement, read up here.
$template = get_post_meta( get_the_ID(), '_my_theme_post_template', true );
switch ( $template ) {
case 'template-2':
get_template_part( 'inc/post-loops/template-1' );
break;
case 'template-1':
get_template_part( 'inc/post-loops/template-2' );
break;
default:
// Neither values matched, do something else?
break;
}
Related Posts:
- How to show a custom meta box on the “Quick Edit” screen?
- Reset positions of metaboxes in admin
- Theme elements not translating
- Why is save_post triggered even when I havent saved the post
- Appending a value to metabox before and after saving
- How do I obtain the post content via a custom meta box inside the editor?
- More than one meta field in a single meta box?
- wp_editor() usage in custom meta box
- Is there a need for nonce with Post Metabox?
- Custom metabox for custom page template
- Custom Field created in add_meta_boxes reappearing itself again in the default Custom Metabox
- Where WordPress Stores The Custom Fields Values
- Wpautop in wp_editor not working
- How to set Post meta-box defaults based on the choices made by user in Customizer?
- Load different single.php templates according to post layout selection
- Output richtext metabox value
- show_option_none not working in meta box
- Find callback function of custom meta box
- Create new sidebars trough admin post/page metabox
- Get all Custom Post Types
- Adding Metabox Value Using the content filter
- Support Multiple featured images
- Add custom field to existing meta box?
- How do I remove a pre-existing customizer setting?
- wp_redirect() – headers already sent
- Enqueue Stylesheets After Theme’s “rtl.css”
- Why I can’t add a CSS style in this WordPress theme?
- Use __($str) and _e($str) to translate strings with HTML
- Posts in multiple Categories different single.php
- Single Page WordPress Theme – Using page templates
- Confused about image sizing business in WordPress
- Creating the modern ‘single page’ html5 css3 layout in wordpress
- How can I stop WP media uploader from creating duplicates of my uploaded images?
- How to override BuddyPress 3.0 bp-nouveau theme files?
- Responsive Images – Generating multiple images from Theme Customizer control upload?
- How can a Theme Contain no Header File or Footer File?
- WordPress theme (or plugin) that uses Contenteditable property
- Adding “latest from the blog” to the homepage
- Default comments file and how to copy it
- Changing order title and featured image in blog post (Astra theme)
- Is there a theme function for is_password_protected()?
- Some translations do not work in my template class
- WordPress not registering Theme Customization Section
- How to get comment meta values by post ID
- Why is the Links Manager visible?
- Find the Children of a Page then Echo it as a Bulleted List of Links (menu)
- Check if home.php and set home.php as page_on_front
- Should I use add_filter for functions in function.php of the theme?
- Multiple TinyMCE Editors in one Admin Page
- Showing a list of posts when homepage is custom
- Retrieve localised value
- How to disable wordpress from overload my stylesheet styles with customizer styles
- AJAXIFY WordPress Theme Frontend menu
- How can my theme allow users to take advantage of advanced html tags in posts
- Pull request in WordPress repository?
- How to Call pages from a Options Panel
- How can I conditionally show different home page templates based on whether or not the user is logged in?
- how to get the post attachement image in full size?
- Gallery thumbnails very small
- Is there a list of all display functions for templates? [closed]
- Using a starter theme vs starter theme with child theme
- How should I use starter content utility to show some default menus?
- Set a featured image as a replacement to the header image
- How to remove ID’s from wp_enqueue_style?
- How to include Google fonts [duplicate]
- Theme Customizer not displaying saved values in wp_head (CSS)
- Create a category archive page in TwentyTen Child Theme
- How to call the_time current?
- Thesis -style Navigation
- White screen when attaching css to function.php
- Different text on different sites in a multisite setup
- How to remove WP Title Tag?
- Retrieve WordPress’ the_content() with jQuery
- How to create a WP theme that use BootStrap? [closed]
- Alternatives to handle customizer settings
- Theme Checker Text Domain
- Minimal WordPress Functionality on Existing Website
- W3 total cach and theme changes [closed]
- loading javascript after jquery is loaded
- Change default rel attributes for Image Block & Button Block
- How to copy page/post from one theme to another?
- Not sure how to debug this npm install error. This is a wordpress theme that comes with a built-in gulp/webpack task automation [closed]
- Using has_term() function for category-subcategory structure
- Find the source file causing a Mixed Content warning
- Ajax Comment Upvotes – Votes don’t always register
- Are paginated comments required for publishing Themes?
- Modify comments_popup_link output
- How can I display and excerpt of all pages with a meta_key and meta_value on index.php?
- Can you create a custom page with content in the center already defined?
- Enable WP to accept standard jQuery code embeding between the tags [duplicate]
- Pagination issue with Single.php
- php file child theme directory not overriding parent theme php file [duplicate]
- How do I change the tagline input to textarea?
- Creating completely new WordPress site from old WP contents
- Should I create a child theme for a parent custom theme? [closed]
- How to make a multilingual wordpress site to be translated one-to-one without much effort and without using translate?
- Theme template file for a specific custom taxonomy
- How do I work with responsive images in WordPress? (img srcset/sizes)
- How can I use pre declared blocks in a php file?
- jQuery Snippet Not Working on WordPress Site [closed]