I have a blog and on the main page are 3 blocks of posts. So, I get these posts with "get_post" and I have 3 similar codes on page:
global $post;
$args = array( ... );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
.......
<?php endforeach; ?>
I have a hight load of CPU and I wonder if I will use "wp_query" will save my CPU. Thanks.
Here are my get_posts() queries:
<?php
global $post;
$args = array( 'numberposts' => 5, 'offset'=> 0, 'category' => "1" );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_title(); ?>
</div>
<?php endforeach; ?>
<?php
global $post;
$args = array( 'numberposts' => 7, 'offset'=>0, 'category' =>"2 , 4 , 6 , 7 , 9 ,10,11");
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_post_thumbnail(array('size' => 300,300), array('title' => '')); ?>
</div>
<?php endforeach; ?>
<?php
$args = array( 'numberposts' => 15, 'orderby' => 'rand' ,'offset'=>0, 'category' =>"31");
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php the_title(); ?>
</div>
<?php endforeach; ?>