Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9129761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:49:19+00:00 2026-06-17T07:49:19+00:00

My problem is that I am displaying some posts from the category events. Then

  • 0

My problem is that I am displaying some posts from the category “events”. Then a bit later on the same page I want to display a random post from the category “spiller” and that works fine. It gets a random post, shows the title, the thumbnail, but when I say show the_content (or the_excerpt), it shows all the content (or excerpts) of the posts in the category “events”. Please help me solve this!

<div class="well span6 Padding10">
    <h4 class="titleFont MarginBottom20">KOMMENDE BEGIVENHEDER</h4>
    <?php
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $args  = array(
        'category_name' => 'events', // Change these category SLUGS to suit your use.
        'paged'         => $paged

    );
    query_posts( $args ); ?>
    <ul>
        <?php
        while ( have_posts() ) : the_post(); ?>
            <li>
                <a href="<?php the_permalink(); ?>"><strong><?php the_title(); ?></strong></a>
            </li>
        <?php endwhile; ?>
    </ul>
</div>

<div class="span6 well" style="height: 250px;"><h4 class="titleFont">SPILLER HIGHLIGHT</h4>
    <div class="row-fluid">
        <?php
        $args       = array(
            'numberposts'   => 1,
            'orderby'       => 'rand',
            'category_name' => 'spiller'
        );
        $rand_posts = get_posts( $args );
        foreach ( $rand_posts as $post ) : ?>

            <div class="span5"><?php the_post_thumbnail( array( 150, 150 ) ); ?></div>
            <div class="span6 MarginTop10">
                <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
                <!-- THIS IS WHERE IT MESSES UP: --><?php the_content(); ?>
            </div>
        <?php endforeach; ?>
    </div>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:49:21+00:00Added an answer on June 17, 2026 at 7:49 am

    First of all, you need to avoid using query_posts. It affects a lot of WordPress Globals, and alters the Default Loop which – unless this is your specific intention – absolutely needs to be avoided as it can lead to performance issues as well.

    Please look into substituting query_posts with WP_Query instead.

    Apart from that, you need to reset your postdata, as well as set up your new postdata in the next loop.

    Resetting The Query::

    <?php 
    while ( have_posts() ) : the_post(); 
    ?>
    <li>
        <a href="<?php the_permalink(); ?>"><strong><?php the_title(); ?></strong></a>
    </li>
    
    <?php endwhile;wp_reset_query(); ?>
    

    Set up:

    foreach( $rand_posts as $post ) : setup_postdata($post); ?>
    

    Reset The Postdata:

    <?php endforeach;wp_reset_postdata(); ?>
    

    Why does this need to be done?

    Anytime you’re using one of those handy WordPress functions prefixed with “the_”, that function is referencing the $post Global. query_posts changes that Global (as mentioned above) and if you plan on referencing that Global in a separate Loop, you need to be able to change it again on the fly.

    Resetting your queries is just good general practice in making sure that all of your Globals are back to the WordPress Defaults. But setup_postdata($post_object) is what actually allows us to change that Global to the current object in our custom loop.

    The reason why WP_Query is so effective is that resetting the query is no longer essential as the WP_Query Loops are localized to that particular Object, and doesn’t modify the Global $wp_query (which incidentally affects a LOT of other globals).

    Here’s some handy information about query_posts vs WP_Query that should explain things a little better for you.

    Hops this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that includes displaying some photos from a user's Facebook account.
I have a problem that I'm working on for quite some time now. I
Im currently facing the problem that when i try to set focus on some
I have the same problem that is listed in the following thread. WSDL first
I have an edit view that is displaying some model properties as plain text
I am using HighCharts for displaying some statistical data but i have a problem
I want to create a django app that can upload and display images. However
We need to create a web-based frontend for displaying some data. The problem is
I created a little script that imports wordpress posts from an xml file: if(isset($_POST['wiki_import_posted']))
We are displaying some text in text box coming from database. We set this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.