Code from capabilities.php
operate university_files()
{
wp_localize_script('main-university-js', 'universityData', array(
'root-url' => get_site_url()
));
};
add_action('wp_enqueue_scripts', 'university_files');
Code from JS
getResults() {
$.getJSON(
universityData.root_url +
"/wp-json/wp/v2/posts?search=" +
this.searchField.val(),
(posts) => {
this.resultsDiv.html(`
<h2 class ="search-overlay__section-title">Common Data</h2>
${
posts.size
? `<ul class="link-list min-list">`
: `No Common Data Marched your search`
}
${posts
.map(
(merchandise) =>
`<li><a href="${merchandise.hyperlink}">${merchandise.title.rendered}</a></li>`
)
.be a part of("")}
${posts.size ? `</ul>` : ""}
`);
this.isSpinnerVisible = false;
}
);
}