WordPress.org

Ready to get started?Download WordPress

Forums

Add custom post above page content (3 posts)

  1. SchuminWeb
    Member
    Posted 2 years ago #

    Having a problem with a page template. What I'm trying to do is get the content from a custom field to output above the page content. In other words, this:

    Page title
    --
    Custom field output
    --
    Page content

    What it's doing is outputting the three custom post type entries as described, but then when it's time to do the regular page content, it outputs the three custom posts again, but this time formatted like the page content was supposed to be.

    This is the code that I'm using to do this:

    [code moderated - the forum limit for posting is 10 lines - for more, please use the pastebin]

    What am I doing wrong? This should work...

  2. Frumph
    Member
    Posted 2 years ago #

    Try not to overwrite the global $wp_query do something like this instead:

    <?php
    $wp_query->in_the_loop = true; $addedLoop = new WP_Query(); $addedLoop->query('post_type=site_updates&post_status=publish&paged=$paged&posts_per_page=3');
    // var_dump($addedLoop); - uncomment this to check the contents returned
    while ($addedLoop->have_posts()) : $addedLoop->the_post();
    
    <li><p class="smalltext"><B><?php the_time('F j, Y'); ?>, <?php the_time('g:i A'); ?></B> – <?php the_content(); ?></p></li>
    <?php
    endwhile;
    wp_reset_query();
    ?>

    ya

  3. SchuminWeb
    Member
    Posted 2 years ago #

    That got it! Thanks much. You did leave out a ?> in your code, however, so here's the final code that I ended up using:

    <?php
    $wp_query->in_the_loop = true; $addedLoop = new WP_Query(); $addedLoop->query('post_type=site_updates&post_status=publish&paged=$paged&posts_per_page=3');
    // var_dump($addedLoop); - uncomment this to check the contents returned
    while ($addedLoop->have_posts()) : $addedLoop->the_post(); ?>
    
    <li><p class="smalltext"><B><?php the_time('F j, Y'); ?>, <?php the_time('g:i A'); ?></B> – <?php the_content(); ?></p></li>
    <?php
    endwhile;
    wp_reset_query();
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic