Examples or docs? #224
Comments
@scottopolis Thank you. You're right, the postmeta fields you add to a metabox on the edit post admin screen will not automatically show up in the Customizer. Even with the new 4.6 API for registering meta, these fields will not automatically appear (see #192 to start a discussion on that). But actually the Featured Image is, in fact, postmeta. For one, you can refer to the featured image code in the plugin for how it is accomplished there. Additionally, the Page Template is also postmeta, so you can refer to that. I also have a quick-and-dirty single-file plugin example (somewhat contrived) for how to add a postmeta for injecting some text before a post in The Loop: https://gist.github.com/westonruter/f8473159e48fbacbef9dcd6498155846 The code should be refactored and cleaned up some more to be a better example, but all of the pieces are there, including:
|
And actually, if you have some ideas for good example postmeta that could be added as Customize Posts examples, that would be good too. |
Thanks Weston! |
I'll keep this open because I want to add the example to the readme. |
Hey Weston, your example works great, I'm trying to use a select menu instead of the post editor, but I'm not able to get this to save. Any idea why? https://gist.github.com/scottopolis/66b0b631b328309ce959dff9766abda8 (Everything shows correctly, I added post type support in another file, it just doesn't save) |
Nevermind, figured it out. Forgot to add input_attrs to params. I updated the gist if you want to use it as an example of a custom select menu for post meta. |
Hey guys, thanks for building this plugin and those examples. I'm experimenting with this and I've built a quick and dirty plugin expanding on those examples. Basically is parses a JSON file full of info for Custom Post Meta and adds the fields to the customizer. Definitely needs some work, but it seems to be working on my test site for 'text', 'checkbox', 'select' and 'post_editor' controls. https://github.com/Invulu/custom-customizer-postmeta Just thought I'd leave that here for anyone looking through the thread. |
Hi @westonruter, I'm really excited about this plugin and the direction of the customizer! Thanks for putting so much time into this. I'm hoping to add a module to our themes that will add customizer support for Custom Post Meta, but I'm struggling a bit to understand exactly how all this is working. I've got an example plugin built from your earlier example that has successfully added some CPM fields to the customizer. But I've run into some issues with the selective refresh. I'm using it for some text fields, and when editing the text fields, it just inserts the CPM text field value into the selected element on the page. How would I go about connecting a custom selective refresh partial to render that change? Would that be something I could do through the params below?
Also is there any documentation for what the valid parameters are for that api.controlConstructor.{control type} call? I'm trying to add a default value to a checkbox CPM field.
I've been trying to dig into the code, but between this plugin and all the core stuff it's a lot to take in, if you could point me to specific docs, classes or files I should be looking at to understand this, that would be awesome! |
@jqlee85 hey, the properties of As for an example, I'd suggest the single-file example I reference above: https://gist.github.com/westonruter/f8473159e48fbacbef9dcd6498155846 For specifying the default value in that example, you'd do so in the call to |
Hey guys, this looks like an awesome plugin. I'm excited to use it, but I'm confused how to add/remove post meta to the customizer.
I have a custom post type with a bunch of registered meta fields, but none of them show in the post customizer. Do you have example code for adding/removing post meta fields?
Thanks!
The text was updated successfully, but these errors were encountered: