Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type and need to display it in a certain way. I would like other posts to display as normal. When I tried to use the following code to accomplish this, I get a 500 Internal Server Error.

global $post;


//do this only for custom type
  if (!(get_post_type()=='customt'))
  {
    $rawContent = $post->post_content;
    $formattedContent = apply_filters('the_content',$rawContent);
    echo $formattedContent;
    return;
  }

I have googled around and found a lot of things regarding .htaccess but I don't think that is the case here. If I comment out the apply filters line ($formattedContent =...) and echo raw content, the post displays, but without formatting of course.

What am I doing wrong when I am trying to apply a filter?

share|improve this question
    
Please show the function as a whole, not just the snippet. –  kaiser Jul 24 '12 at 3:18
    
I am certain that this is the path it's going down. If I echo something instead of apply filters(including just $post->the_content) it come out correctly. –  fdsa Jul 24 '12 at 3:38
    
I asked you to post the whole function. Could you please do so for later readers? It would also be good, so we can enhance our answers to a real solution. Else it will be closed as too localized. –  kaiser Jul 24 '12 at 12:50
    
I think it probably should be closed..I had a variety of unrelated issues. –  fdsa Jul 24 '12 at 15:05

2 Answers 2

up vote 0 down vote accepted

Please try to replace your snippet with the following. The global $post isn't needed, when it's outside a function or method context and inside the loop, as then $post is already global and get_post_type()s default false arg with be replaced with $post inside the function.

if ( 'customt' !== get_post_type() )
    return print apply_filters( 'the_content', $post->post_content );

Also make sure, that you're not calling it on some too early filter, like plugins_loaded or init, as the global $post object wouldn't be setup up.

share|improve this answer
    
This is the closest...I'm still having issues but I was calling with init which didn't help things. –  fdsa Jul 24 '12 at 4:10

Post type name shouldn't contain capital letters.

Also try pass $post object to get_post_type() function

Like this:

if(!get_post_type($post)=='customT'){
   //code
}
share|improve this answer
    
Sorry to lead you down the wrong path - the custom post type is lower case letters, I was just trying to make it more generic. I am confused about the second part of your answer as the code in the if block is running when appropriate, apply_filters is just not working right. Thanks for the quick attention –  fdsa Jul 23 '12 at 20:22
1  
anything form php error log? –  Sisir Jul 23 '12 at 20:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.