Your second function is wrong. get_post_type($post)
excepts the current post object or post ID or any post object or ID given to it. You are using the arguments for get_post_types( $args, $output, $operator )
for get_post_type
, which fails the function which in turn gives you the error in your foreach
loop.
To rectify your function, use something like this:
add_filter('single_template', 'my_single_template_folders_terms');
function my_single_template_folders_terms($template) {
global $post;
$post_type = get_post_type($post);
if ( file_exists(TEMPLATEPATH . "/{$post_type}/single.php") )
return TEMPLATEPATH . "/{$post_type}/single.php";
return $template;
}
Related Posts:
- Use a separate upload folder for custom post attachment upload
- How to create a mini directory in WordPress?
- Post Ancestor and Child Post in Custom Post Type
- Want to turn WordPress into a paid subscription directory
- Custom post types with custom directories
- Is it possible to place custom post type files inside a folder in theme directory?
- uploading images to specified directories
- Mapping Subdomains in WordPress to give the appearance of a localised site, best approach?
- Custom Path/Folder behind a custom post type
- How to produce a sub-page-system in WordPress
- How to add a sub directory to WordPress single posts without affecting other post types?
- Building a Data Intensive Website with WordPress
- Yelp-style geographic directory plugin?
- Need folder for CPT templates for eg: single-{post_type}.php
- How to hook into the CPT’s title placeholder?
- How to set a fall back template for a custom post type in a plugin?
- Post formats “audio” and “video” only showing in index.php
- how do I group content in magazine-style ‘issues’?
- Semantic URL Custom Post Type and Taxonomies permalinks
- Set post to draft after set period based on post_modified date
- WordPress custom post action hook
- Display metabox conditionally
- How to remove thumbnail sizes for specific post type on a child theme?
- Do attachments added to custom post types have a post parent?
- How to make an archive page displaying posts in a date range
- Categories and Tags not working!
- category.php displays ALL posts instead of just those with the current category
- Custom Post Custom Taxonomy Data Not Saving in Edit Screen
- Display Next/Prev when looping Custom post-types archive?
- List custom posts by custom taxonomy
- How to Set Post Status to Draft if older than today
- How much control do we have over CPT rewrite slugs? Can I create a “root” page for my CPT with out the page path, and then have paths for other pages?
- Create a post in custom post type using field in registration form after users submit form
- Display CPT posts based on specific taxonomy
- Wrong generated page_name/slug on first publish of custom post type
- Can’t change first part of URL rewrite for custom post type
- Get all properties of custom post type
- Add predefined/default values to custom post plugin
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Hide editor while keeping add media button in custom post type
- dynamically add a custom field or metabox to custom post type [duplicate]
- How to use custom taxonomies to reference complex relationships?
- How to implement a Google map store locator
- CPT EVENT – listing by month and filtering by category and month – form select option
- custom post type WYSIWG removes paragraphs when displayed
- ACF field key/value to show on taxonomy list
- Re-registering a custom post type not working (not showing up)
- WP Rewrite Rule Issue while using Custom post type & taxonomy
- Lists custom taxonomy terms that has specific custom field value assigned to the term (not post)
- How can the recipients and content for comment email notifications on a custom post type be changed?
- Meta Query posts not showing on ending date of custom field
- What is best way to prevent access to Custom Post Types unless authenticated when the post type has an archive and is publicly queryable?
- Hierarchical custom fields
- Specifying Mouseover Icon for Custom Post
- 4 column-loop ordered alphabetically with entries grouped (and labeled) by their first letter
- Is there something like has_no_term
- what custom post type this archive belongs to?
- Custom post-type metabox position
- Post will not load via ajax
- Displayling list of Custom Post Type Posts
- List of Categories for Custom Post Type
- WordPress admin display post type tags as checkbox
- $post->post_meta not pulling any post in wordpress/php
- WordPress custom API endpoint – how to make the request more flexible
- Custom Post Type posts not showing in category
- Need alternative get_posts function for custom post type
- How to get post type information?
- importing table data to custom post type
- is it possible in a custom post, create custom fields as well whitin?
- Take stored email addresses from custom post type & turn into one string
- WP_Query order custom post type with certain meta key value by post modified date
- How to show multiple images in a slideshow for a portfolio page
- restricting custom rewrite to just one custom post type
- How to show custom posts
- Pagination in custom post type archive.php not working
- How to filter a matched value with custom key using WP REST API?
- how to display author name in custom post type
- create a “add icon” field in taxonomies page
- Custom Post Type Pagination getting 404 error
- How to search through all child taxonomies using WP_Query?
- Custom Post Taxonomy Template Not Loading Properly
- WordPress retrieving $post based on random key in $_POST
- How can I use one instance of page.php to display different custom post types?
- Show ajax form resuslts in page
- PHP Notice: Unidentified index
- Unwanted URL with Custom Post Type
- wp_nav_menu doesn’t seem to work on custom post type pages
- Custom meta box in editor of custom post type not working
- Multiple custom post type and permalink issue
- Using mediaelement to display gallery of audio
- Help ordering custom query by Title, Ascending
- group posts by month/date ignore years
- change precedence of permalink for post_types?
- Toggle a metabox based on a selection
- Image paths on custom post types getting /post_type/ added to path
- Problems with custom post type and hierarchical permalinks
- Issue on Adding Taxonomy to Custom Post Type Using Function
- Trying to display next and previous set of posts on separate page (not parent page)
- How is it possible to list custom post types by “category” like with simple posts?
- Taxonomy Archive URL + Template