1

Is there a way to get query with post information (thumbnails, id, etc.) but without the_content()?

I already have plugin to show recent posts in sidebars at homepage and when it is for example 20 posts and content of every has 1MB it loads 20 MBs of content at home page which at the end is not displayed because it only shows thumbnail, title and vote/comment options. It kills the website. Is there a way to load post info to this plugin with query but excluding post's content to be loaded?

Code:

<?php $recent=new WP_Query(); ?>
        <?php 
                        $recent->query(array(
                    'post_type' => get_post_types(),
                    'cat' => 26,
                    'showposts' => 3,
                    'ignore_sticky_posts' => '1' ));
                     ?>


        <ul id="tab-recent" class="alx-tab group <?php if($instance['recent_thumbs']) { echo 'thumbs-enabled'; } ?>">
            <?php while ($recent->have_posts()): $recent->the_post(); ?>

            <li>        
                <?php if($instance['recent_thumbs']) { // Thumbnails enabled? ?>
                <div class="tab-item-thumbnail">
                    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                        <?php if ( has_post_thumbnail() ): ?>
                            <?php the_post_thumbnail('thumb-small'); ?>
                        <?php else: ?>
                            <img src="<?php echo get_template_directory_uri(); ?>/img/thumb-small.png" alt="<?php the_title(); ?>" />
                        <?php endif; ?>
                        <?php if ( has_post_format('video') && !is_sticky() ) echo'<span class="thumb-icon small"><i class="fa fa-play"></i></span>'; ?>
                        <?php if ( has_post_format('audio') && !is_sticky() ) echo'<span class="thumb-icon small"><i class="fa fa-volume-up"></i></span>'; ?>
                        <?php if ( is_sticky() ) echo'<span class="thumb-icon small"><i class="fa fa-star"></i></span>'; ?>
                    </a>
                </div>
                <?php } ?>

                <div class="tab-item-inner group">

                    <p class="tab-item-title">
                                            <?php $posttitle = get_the_title(); ?>
                                             <?php if (strlen($posttitle) > 19) {
                                        echo '<a href="' . get_permalink() . '">' .substr(the_title($before = '', $after = '', FALSE), 0, 19) . '...' . '</a>'; 
                                     } else {
                                            echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
                                    } ?>
                                            </p>
                <div class="content">
                    <?php the_content(); //I WANT REMOVE THIS LINE ?>
                </div>

<div class="stats">
    <div class="recommendation">
        <?php if(function_exists('wpv_voting_display_vote')) wpv_voting_display_vote(get_the_ID()); ?>
    </div>
    <div class="comments-count">
        <?php comments_number( '0', '1', '%' ); ?>
    </div>
    <div class="clear" style="clear:both;"></div>   
</div>

                </div>

            </li>
            <?php endwhile; ?>

I dont say every post has 1MB. I just give example. For now, loading home page gets 50% more time because sidebars load whole content of posts what is pointless and I want to change this without heavy recoding of plugin.

Also as you can see, there is 'showposts => 3' but there are 6 boxes with posts with other categories so it gives total of 18 posts to load.

I want to remove line with the_content(); because it only shows one sentence and its not worth to load whole post content.

3
  • 2
    Post your current query code. Commented Apr 2, 2015 at 13:31
  • This sounds like a content problem. If each post is 1MB, your site is always going to be slow.
    – jdm2112
    Commented Apr 2, 2015 at 13:33
  • 1
    Without seeing the code we can't determine the method you're using for grabbing posts or how you're working with them, which we need in order to answer the question. Can you click the edit link on your question and add the code?
    – Tom J Nowell
    Commented Apr 2, 2015 at 13:44

1 Answer 1

0

If you set the fields argument to ids in your query it will return only post IDs which you can then pass to other functions to fetch the data you need. Though that may save memory at the cost of increasing queries to the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.