A long time ago, I put a post up about getting ACF Fields for a custom post type in the WP JSON API response but you’d have to do that one by one. Sometimes that would be good but if you have a lot of fields and don’t mind them being public it’s not so good. So I was looking around and hit this StackOverflow question. This is a nice option for getting all the fields . . . as long as you remember to change the filter name to be rest_prepare_YOURCUSTOMPOSTYPENAME then it’ll work for any custom post type. Otherwise you’ll think it doesn’t work.
Origin Story Matt worked long hours making an incredible theme for Footprints on the James course.1 It’s in WordPress but a large portion of the site ended up being built by hand as complexity increased and time dwindled.2 That means it’s hard-coded HTML/PHP. Now because the site was so great, we ended up having a conversation with the faculty involved a few months after the site was finished. They want to run the course on other rivers and want similar sites for those rivers. That means we need to turn this site into something that is more like a traditional WordPress theme. I’m taking the first stab at that and felt it’d be an interesting thing to write about a bit. Analysis My first move was to tackle the front page as it has the most complexity. I drew this on a whiteboard but I included a fancy image below because I wanted to make it nice for you. Now we can see two columns for content on this page type. In the ‘sidebar’ column we see quotes and HTML elements, maybe some more. In the ‘main’ column, we see HTML elements and elements that span the sidebar and main column. The goal is to figure out how to chop this stuff up so that people can write it using […]
Origin Story We have someone who wants to allow people to enter various numbers of items in a particular pattern. We want to keep this as easy as possible and they wanted to avoid having to repeatedly hit submit. First Pass – Gravity Forms Repeater Field I initially thought we could do this in Gravity Forms using the beta repeater field option. I used example #2 this time. It lets you reference another form as a repeater field inside the parent field. This example uses the form with ID 1 as the parent and ID 2 as the included repeater. This worked great except it has issues with file uploads which canceled it out for our uses. This will work nicely for repeaters that aren’t dealing with those field types. And this pattern can be tossed in a plugin without modification with the idea that the first form you make will be the holder and the second form will be the repeater. Second Pass – ACF with Advanced Forms After seeing that fail, I debated writing something to customize the file upload in Gravity Forms but figured I’d try ACF first. ACF has repeater fields and I recalled using acf_form() in a project a while back but wasn’t sure how it’d handle repeaters. Prior to doing it from scratch, I […]
Origin Story Kathy asked me if I had any grade book plugins that they could use with a faculty development course. The goal was to show faculty where they were in the course. I knew I did not wish to use Learn Dash for any number of reasons– grade book module costs extra, grade book module is super awkward, learn dash requires a fresh multisite install etc. I also had WPLMS from a few years ago when I think Jon asked to try it out. This felt pretty bloated for what we wanted and it wasn’t entirely obvious if it had a grade book in any case. The WordPress plugin repository shows three plugins and the most up to date has not been updated in 3 years. Not a cheerful landscape. I wondered what it would take to build an ACF-based grade book relying mostly on the repeater field and simple shortcode for displaying the grades to the user. I wasn’t looking to do math or anything. I just wanted a pretty simple interface and a way for users to see their information while administrators could see all the content. That does require people to have accounts and be logged in. A bit of hassle but there is no free lunch.1 This grade book isn’t adding up things or doing […]
When you use Gravity Forms to make a post, you can provision ACF fields but what I found was that the data wasn’t showing up correctly until I manually went and updated the created post. I tried using the WordPress wp_update_post() function but found that didn’t do it. I ended up taking a look at the post_meta in the database directly.1 That’s something that I find myself doing more and more. When you can look directly at evidence, do that. Don’t assume. So what I saw was this . . . You can see that the base custom fields are there. The data is visible. Now I hit update and refreshed the database view and saw lots of new custom fields get generated. This data associates the human readable fields with the field keys that ACF creates. Note the underscores which prevent those fields from showing up in the backend of WP even if you have view custom fields selected. I feel like this has something to do with acf/save_post but couldn’t figure out how to make that work. When my knowledge fails,2 I resort to force. First, I turned on the ability to see the field keys in ACF. It’s easy to miss and easy to forget that this is a Screen Option in WP. Once I could see […]
We have a bunch of world language professors prying at the edges of Pressbooks. One of the requests yesterday was to be able to create a mini-dictionary of target language words at the beginning of sections written in that target language. Mousing over the words would show their English equivalent. The intent is to have ready assistance for those who need it so that writing in the target language can happen earlier in the course. ACF came to mind pretty quickly for this case. I really just needed the ability to generate two values that are paired together- the target language word and the English definition. I need to be able to make as many of these pairs as the person wants to put in there. That’s custom made for the ACF repeater field. Now that I had an easy way for people to add the words, I just needed a way to do the tooltip display. There are 12,000 ways to do this but I just looked around for one that bragged on its accessibility. I found this example on codepen and went with it. This bit of php builds that content. Now that we have the the content and way to handle the tooltip piece, I needed to stick it at the top of the posts. That’s just […]
If you use Advanced Custom Fields you may not realize it removes the ‘Custom Fields’ option from your Screen Options view and hides them entirely in the space they normally occupy below your posts/pages. That’s nice occasionally and a pain other times. Today it was a pain. I figured this out one time before but it took me a while to re-find it at this github page so I’m leaving it here in case I forget again.