Map wordpress post from array

So I have the following function:

/**
 * Get array of post objects
 *
 * @param slug
 */
function get_array_of_post_objects(slug)
{
    let items = [];
    wp.api.loadPromise.done(function () {
        const Posts = wp.api.models.Post.extend({
            url: wpApiSettings.root + 'menus/v1/locations/' + slug,
        });
        const all_posts = new Posts();
        all_posts.fetch().then((posts) => {
            items.push(...posts.items);
        });
    });
    return items;
}

When invoked like this:

const test = get_array_of_post_objects('application_launcher');
console.log(test);

Gives me an array of objects as shown below:
enter image description here


Question:

What would be a good way to map my objects? Let’s say that I want to map just the ID and db_id.. what’s a good approach? I haven’t messed with mapping too much, so have some learning to do.

Here is what I was messing with:

const test2 = test.map((ID, db_id) => {
    return {
        ID,
        DBID: db_id,
    }
});

49 thoughts on “Map wordpress post from array”

  1. pharmacie galerie beaulieu nantes pharmacie leclerc ancenis , act therapy anxiety therapie de couple drummondville , Budecort livraison Canada, Budecort livraison Canada. Budecort pharmacie Canada Budecort pas cher [url=https://troublesvsprov.asso-web.com/#]Budecort livraison Canada[/url] pharmacie de garde aujourd’hui a koumassi Alfusin moins cher, Acheter Alfusin mens health pas cher. Alfusin sans ordonnance France Alfusin pas cher [url=https://troubles12is.asso-web.com/#]Alfusin livraison France[/url] , pharmacie aix en provence horaires pharmacie arthaud amiens , therapie de couple yverdon. generique aerius comprime Naltrexone prix sans ordonnance, Acheter Naltrexone 50 mg pas cher. Naltrexone sans ordonnance Belgique Naltrexone pas cher [url=https://troubles48ni.asso-web.com/#]Naltrexone pharmacie Belgique[/url] , pharmacie leclerc cholet pharmacie argenteuil 11 novembre, pharmacie amiens horaires produits alimentaires medicamenteux . pharmacie bailly telephone, traitement gale pharmacie meunier annecy therapie comportementale et cognitive macon .

    Reply

Leave a Comment