WordPress.org

Ready to get started?Download WordPress

Forums

cache_results and WP_QUERY (1 post)

  1. mayuxi
    Member
    Posted 8 months ago #

    Good WordPress people,

    I'm trying to speed up my blog's frontpage, where I have many custom queries (made with WP_Query). Today I found out about "Caching Parameter" (cache_result and others) and want to give it a try. It says:

    In general usage you should not need to use these, adding to the cache is the right thing to do, however they may be useful in specific circumstances. An example of such circumstances might be when using a WP_Query to retrieve a list of post titles and URLs to be displayed, but in which no other information about the post will be used and the taxonomy and meta data won't be needed. By not loading this information, you can save time from the extra unnecessary SQL queries.

    Question: So, does it mean I can use this parameters to optimize my query in case where I just show titles with link from custom post type on my front page?

    Example:

    $args = array(
    			'post_type' => 'outside',
    			'posts_per_page' => 5,
    			'ignore_sticky_posts' => 1,
    			'no_found_rows' => 1
    	);
    	$second_query = new WP_Query( $args );
    <?php while( $second_query->have_posts() ) : $second_query->the_post(); ?>
    
    	<li>
    		<a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a>
    	</li>
    <?php endwhile; wp_reset_postdata(); ?>

    Thanks! Xiexie!

Reply

You must log in to post.

About this Topic