WordPress.org

Support

Support » How-To and Troubleshooting » the_content returning null

the_content returning null

  • hi,
    i have a page loop-page.php and i have used the loop to make what i wanted. i.e

    <div class="headings">
    	<?php the_title();?>
    </div>
    <div class="pages_bg">
    	<?php if(have_posts()):?>
    		<?php while(have_posts()): ?>
    			<?php var_dump(the_content());?>
    		<?php endwhile; ?>
    	<?php endif; ?>
    </div>

    As you can see i did var dump of the output as it wasn’t displaying anything but it came out null.what could be the reason. the content in there in the visual editor?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael
    Forum Moderator

    @alchymyth

    the_content() is echoing the result;
    http://codex.wordpress.org/Function_Reference/the_content

    use get_the_content() if you need it to return the result to be used in strings or conditional statements.
    http://codex.wordpress.org/Function_Reference/get_the_content

    or use apply_filters('the_content',get_the_content())

    ————–
    to test the contents of the post in the loop, possibly try to replace your line with <?php var_dump($post); ?>

    or check directly after <?php if ( have_posts() ) : ?> with this code <?php var_dump($wp_query); ?>

    it didn’t show when i used

    <?php if(have_posts()):?>

    <?php while(have_posts()): ?>
    <?php get_the_content();?>
    <?php endwhile; ?>
    <?php endif; ?>
    </div>

    bt in did gave me dump the way u told me.

    I m trying to style the tags of page.php but can’t find them. as like suppose the title, content etc. doesn’t that comes from loop.php coz i tried finding #respond i.e comment div but couldn’t in loop.php

    your problem is because you haven’t add the_post() before get_the_content. your loop will still null, and you will not get any content.

    itu should be

    <?php while(have_posts()): the_post(); ?>
    <?php get_the_content();?>
    <?php endwhile; ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘the_content returning null’ is closed to new replies.