Site icon Hip-Hop Website Design and Development

Easy methods to acquire the latest posts with out their content material in an environment friendly method?

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:

The remainder needs to be ignored.