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 sites registered via register_post_type and my front page displays my latest posts. Including posts from sites.

Is there any way I can set it up so that posts from sites (custom post type) that have no post body (no content) will NOT be displayed?

The body of the custom post type is not important, the title is. I introduced custom fields for my custom post type. I make a list from custom posts and majority of them do not have any body. So I do not want to display them. It will only make the web harder to read. I want to display only custom posts that have body.

I have not modify the loop.

How can I modify the loop (introduce custom query) as a part of plugin?

share|improve this question
add comment

2 Answers

By default in Wordpress if you create a new post, or custom post type based on post, and fill in the title but no body and press "Publish" it will save it as a draft instead of actually publishing it. If the post is saved as a draft it won't show up in your list of posts during the loop.

Can you elaborate more on why you're trying to accomplish this? There might be an easier solution for the bigger goal.

However, if you do want it to work exactly as specified, you'll To specifically modify which posts go through the loop, you would need to run a custom query.

Did you already modify the loop by adding parameters or doing a custom query? If so, please post that for a start.

share|improve this answer
    
added more info in my question –  Radek Apr 3 '11 at 5:49
    
@Radek thats what @cwd said. posts with no body aren't published, so they won't show up because they would be in draft –  Ashfame Apr 3 '11 at 6:19
    
@Ashfame: it doesn't work for me like that on WordPress 3.0.1. I have just created new post. Entered only title, clicked Publish and I can see it on my home page. –  Radek Apr 3 '11 at 22:58
    
@Radek Oh! I haven't tried that myself, took @cwd words for it. –  Ashfame Apr 4 '11 at 6:31
add comment

Just take the $post object inside your loop and write

if ( ! $post->post_content )
    continue;

to skip the current "round" of your loop if the post has no content.

share|improve this answer
add comment

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.