I have a sidebar is supposed to loop through a bunch of job postings that are fetched from a GET request. The resulting HTML should look like this:
<div>
<h4 class="myapp-sidebar-heaader">Related Positions</h4>
<div>
<a href="#" class="myapp-related-job-link">
<h5 class="myapp-job-title">Job title really really long</h5>
<h5 class="myapp-job-location">Location</h5>
</a>
<a href="#" class="myapp-related-job-link">
<h5 class="myapp-job-title">Job title really really long</h5>
<h5 class="myapp-job-location">Location</h5>
</a>
</div>
</div>
Let's say for now that the API URL is https://jsonplaceholder.typicode.com/todos
.
I found wp_remote_get
( https://developer.wordpress.org/reference/functions/wp_remote_get/ ) but I'm not sure where I put it. Should I just put it in the view file?
I'm guessing I should make a function that:
- Calls
wp_remote_get("https://jsonplaceholder.typicode.com/todos")
- Returns the array of job posting objects
in functions.php, but I'm not sure how I would export it so it would be available in the view.
wp_remote_get
call and parsing to output the HTML.