I just can't get the getCategory function to return anything apart from undefined or false. I've stepped through in the console and all the data is there. I'm still unsure on the best way to make functions call syncronosly
function getCategory(url) {
    if ( url ) {
        let message = false
        $.ajax({
            url: url,
            global: false,
            type: 'GET',
            dataType: 'json',
        }).done( function(data) {
            message = `<a class="post__category post__link" href="${data[0].link}">${data[0].name}</a>`
            return message
        })
    } else {
        return ''
    }
}
function posts() {
    $.get(WPPosts, data => {
        data.forEach( d => {
            const excerpt           = d.excerpt.rendered.substr(0, characterCount)
            const featuredImage     = d._links['wp:featuredmedia']
            const featuredImageURL  = featuredImage ? featuredImage[0].href : ''
            const terms             = d._links['wp:term']
            const category          = terms.filter( term => term.taxonomy === 'category')
            const categoryURL       = category[0].href
            let post = `<article class="column">
                            <div class="decoration decoration__paper decoration__tape decoration__tape--left text-center post">
                                <a href="${d.link}">
                                    ${ getFeaturedImage(featuredImageURL) }
                                </a>
                                <h2 class="post__title">${d.title.rendered}</h2>
                                <p>
                                    ${d.date_gmt}
                                    ${ getCategory(categoryURL) }
                                </p>
                                <div class="post__excerpt">
                                    ${excerpt}... <a class="post__link" href="${d.link}">Read more</a>
                                </div>
                            </div>
                        </article>`
            post = $.parseHTML( post )
            postsWrapper.append(post)
        });
    })
}
I am trying to avoid the { async: false } option
 
    