• hi
    my problem about template hook and detect post type

    this code don’t work!

    add_filter('template', 'echo_post_type');
    function echo_post_type($template){
    	if ( !is_admin() ) {
    		global $wp_query;
    		echo $wp_query->post->post_type;
    
    		//or
    
    		global $post;
    		echo $post->post_type;
    
    		exit();
    	}
    }

    why?

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

    (@jdembowski)

    Forum Moderator and Brute Squad

    What are you trying to do? Display or act on the post_type outside of the admin page i.e. within a post or page?

    As you probably know the is_admin() checks if you are on an admin page and not if you are an admin user.

    You might have better luck with this instead (if you want to work with the post).

    add_action( 'the_post' , 'echo_post_type' );
    Thread Starter Parsa

    (@parselearn)

    tnx, i need detect post type for change website theme
    in page setting plugin, user can specific theme for post type (example: news).

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get post_type in template hook’ is closed to new replies.