WordPress.org

Support

Support » Themes and Templates » [Resolved] $post Object Disappeared

[Resolved] $post Object Disappeared

  • I have created a custom post type called ‘fabrics’ and then a template called ‘fabric.php’. Then in ‘functions.php’ i have added the following code:

    register_post_type('fabrics', array(
    	'label' => __('Fabrics'),
    	'singular_label' => __('Fabric'),
    	'public' => true,
    	'show_ui' => true,
    	'capability_type' => 'page',
    	'query_var' => false,
    	'_builtin' =>  false,
    	'rewrite' => array("slug" => "fabrics"),
    	'supports' => array('title', 'editor', 'excerpt', 'custom-fields', 'thumbnail', 'page-attributes', 'revisions')
    ));
    
    add_action("template_redirect", 'my_template_redirect');
    
    function my_template_redirect()
    {
    	global $wp;
    	global $wp_query;
    	if ($wp->query_vars["post_type"] == "fabrics")
    	{
    		if (have_posts())
    		{
    			include(TEMPLATEPATH . '/fabric.php');
    			die();
    		}
    		else
    		{
    			$wp_query->is_404 = true;
    		}
    	}
    }

    This works fine but i can’t access anything in the $post object and because I have custom fields I can’t get $post->ID for some strange reason. What am i doing wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] $post Object Disappeared’ is closed to new replies.