TwentyTwentyTwo – How to add PHP logic to Post templates?

But how do we “edit and save” PHP code for these templates? Like loops, actions, do_actions, etc… I don’t see the templates being auto generated in my Visual Studio Code environment anywhere….

You don’t, these are block templates, not PHP templates. When in the filesystem in a theme they are plain .html files, and when you modify or create them in the user interface they’re saved in the database.

In order to run PHP code in these templates you would need one of the following:

  • a custom block that renders in PHP
  • a custom shortcode inserted via a shortcode block

This is the same as asking how to run PHP inside a posts content, and the solutions are the same. Custom blocks and shortcodes.