It could be nice to make a single DB request however I do not understand how to do this both. I’ve this code and it really works however I need to change it to be extra environment friendly:
$cs = get_categories(array(
'orderby' => 'title',
'order' => "ASC",
));
$params = array(
'last_five_articles' => array()
);
foreach ($cs as $c) {
$rp = wp_get_recent_posts(array(
'numberposts' => 5,
'post_status' => 'publish',
'class' => $c->term_id
));
foreach ($rp as $idx => $crt)
{
$rp[$idx]["post_content"] = NULL;
$rp[$idx]["url"] = esc_url(get_permalink($crt["ID"]));
$rp[$idx]["is_current"] = $crt["ID"] === get_the_ID();
}
$params['last_five_articles'][$c->slug] = $rp;
}
Replace 1
The fields that I take advantage of from every publish are:
url
(customized area)is_current
(customized area)post_title
post_date
The remainder needs to be ignored.