Before I ask my question, I just want to give a huge thanks to everyone on this forum. I’m brand new to WP theme dev and working with Sage, and have been asking frequent questions. Everyone here has been more than helpful, and it is very much appreciated!
That being said, I’m in need of a little more guidance. Recently, I’ve started playing with ACF Pro and the repeater fields. The repeater field group has its own ID (in my case, portfolio_work), and then the subfields have their own name/IDs (portfolio_image, portfolio_description, etc…). How would I go about pulling that data using Controllers?
@foreach($projects as $project)
<li> @include('projects.project-item', $project) </li>
This isn’t any more “correct” than @MWDelaney’s version: It’s just preference. I like to have controllers return only data, and have views communicate structure. Using @include()instead of a compiled string makes it a little clearer to someone reading the Blade what this element is doing, and keeping the <li> out of the partial makes the partial a bit more flexible. Also array_map() is and has changed my life.
This is good. My way definitely runs the risk of being included without the <ul>.
It’s all personal preference.
I think my way is absolutely preferable if you’re passing instance-specific data, rather than page-specific data, and using a static function. That’s what I’m doing most often and I fell into the habit of doing @foreaches this way from that.
Well first of all, are “shops” items ever repeated among books? Do two or more books have the same shop attached to them? If so, I would use a custom post type (and a relationship field), or custom taxonomy (and a taxonomy field) depending on your needs.
That way you can enter the names and URLs once and reuse them wherever you need.
To diagnose the error you’re receiving we’d need to see your code. What is in your template? What’s is in your controller?
Yes, the second argument passed to array_map should probably be an array.
In this case, my guess is that get_field() returns false or a falsy value when the field is empty, and because that code is using the null-coalescing operator, the expression resolves to the falsey result of get_field(), not . If you use ?: instead (which, in all fairness, is how I should have written this in the first place) you should get the result you want.