WordPress.org

Ready to get started?Download WordPress

Forums

the_content returning null (5 posts)

  1. emaarkhan
    Member
    Posted 1 year ago #

    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?

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    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); ?>

  3. emaarkhan
    Member
    Posted 1 year ago #

    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.

  4. emaarkhan
    Member
    Posted 1 year ago #

    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

  5. jegbagus
    Member
    Posted 1 year ago #

    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; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic