Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5527

kryvonis on "Minifying MySQL queries"

$
0
0

Hi! Calling this function I have much queries to mysql. It shows one newest post from each of 21 categories on front page. Can I do it in one mysql query? Please, help to write a query...

function posts_regions () {
$all_cats_ids = array(2171,2172,2173,2174,2175,2176,2177,2178,2600,2601,2602,2603,2604,2605,2606,2607,2608,2609,2610,2611,2612);
$idp = array();
for ($o = 0; $o < count($all_cats_ids); $o++) {
$args = array(
     'numberposts' => 1
    ,'category' => $all_cats_ids[$o]
    ,'post_status' => 'publish'
);
$result = wp_get_recent_posts($args);
$idp[] = $result[0]['ID'];
}

query_posts(array('post__in' => $idp, 'ignore_sticky_posts' => 1, 'posts_per_page' => 21));
if( have_posts() ){
      while( have_posts() ){
//...
      }
      wp_reset_query();
} else {
   echo 'Error! Sorry...';
}
}

Viewing all articles
Browse latest Browse all 5527

Trending Articles