Forums

Is there a conditional for no content? (6 posts)

  1. Pete
    Member
    Posted 2 years ago #

    is there a way to make a conditional thingy so that IF there is no 'content' in a post THEN ...

    thanks

  2. asechrest
    Member
    Posted 2 years ago #

    Not totally sure, but the global variable $content holds the content of a post.

    So I wonder if you could use if(empty($content)) in some way to check if a post has no content?

  3. Pete
    Member
    Posted 2 years ago #

    I'd love to know how to do this as it would be great to be able to fall back on a custom field if there is no content?

  4. Pete
    Member
    Posted 2 years ago #

    bump

  5. Mark / t31os
    Moderator
    Posted 2 years ago #

    global variable $content holds the content of a post.

    Doesn't work as a global for me (i tested to confirm - inside the loop).

    print_r( $content );

    and then..

    global $content; // To see if the var is actually available just outside the scope of my call..
    print_r( $content );

    Nothing on the page.

    You could use something like ...

    if( empty( $post->post_content) ) {
    // Do whatever you want here
    }
    else {
    the_content(); // Or whatever
    }

    Which does seem to work...

  6. Pete
    Member
    Posted 2 years ago #

    cheers

Topic Closed

This topic has been closed to new replies.

About this Topic