I’m unsure as with everyone else as to what LLM and Generative AI means for our industry and the wider world. Disinformation and the loss of job redundancy in white collar jobs certainly feel like they could spread like wildfire in the near future. But I’m not going to make such predictions here. I’m just going to give an example of how ChatGPT can be incredible useful for a web developer.
During the build of a bespoke WordPress website I wanted to create what’s often referred to as a ‘Mega Menu’ – where hovering over a navigation item displays the list of child pages, but these are displayed with additional icons and descriptive text.
So I added ACF custom fields to the pages, so the user can easily add this info to the page, and that would then pull through to the page listing on the navigation. The trouble was I couldn’t get the fields to display in the custom navigation walker. I spent about an hour trying to figure it out, searching stack overflow, outputting the array in
tags and trying lots of different approches.
In the end I explained the problem to ChatGTP and it instantly understood what I was trying to do, gave me some example code, and then explained where I was going wrong. I was blown away.
In my example, this was it’s response:
In WordPress, when dealing with menu items, $item->object_id and $item->ID refer to slightly different things. $item->ID: This refers to the ID of the menu item itself. It's an identifier specific to the menu item you're currently iterating over. It might be a custom ID assigned to the menu item in the database, but it's not directly tied to a page or post ID. $item->object_id: This refers to the ID of the object the menu item represents. For menu items that represent a specific WordPress object (like a page, post, or custom post type), $item->object_id holds the ID of that particular object (e.g., the page ID if the menu item represents a page). When you're working with menu items and trying to retrieve associated page IDs for ACF fields or other data, you need the specific ID of the page, not the ID of the menu item itself. That's why $item->object_id is typically used because it refers to the associated page ID if the menu item represents a page in the menu. So, in your case, using $item->object_id is more appropriate as it directly points to the ID of the page/post that the menu item represents, allowing you to retrieve ACF fields or other data associated with that specific page.
The issue was I was querying the ID of the menu item rather than the page the menu item is associated with (so I needed to target the object ID rather than the post ID). I would have worked this out eventually myself through trial and error or some nifty Google searching, but this is a perfect example of how LLM’s can speed up development. A common development process is called the ‘Teddy Bear method’ – where you exaplain a coding problem to an inanimate object (e.g. a teddy bear) and in that process of explaining the issue you’ll often work out the problem yourself. One use of ChatGTP is a super-charged Teddy Bear.
Although it feels like there’s an element of ‘turkeys voting for Christmas’ with developers using LLMs to write code for you (as it might one day replace us), ChatGTP is an undeinably an incredibly useful tool; and used correctly can provide an excellent alternative to searching stack overflow (which incidently is how ChatGTP ‘knows’ all this anyway – by reading every open source code avaliable on the internet).
note: I used Adobe Firefly to generate the Teddy image (in about 10 seconds) 🤯 I think we’re all doomed