Comments (2)
Hi @aimeetacchi, thanks for trying this plugin out and sorry you weren't able to get your fields working right away!
First to answer your specific questions:
Are there any code examples or a theme that shows how to set it up? Do I add a field into functions.php
Yes, you'll find lots of code examples at https://fieldmanager.org/, especially throughout the "docs" section. You can also find a repository of assorted examples at https://github.com/alleyinteractive/fieldmanager-demos/. You can add code to your theme's functions.php
file, that is an option. I'll oftentimes do something similar (I'll create a new file just for my fields and require
that from functions.php
). It's also an option to create a new plugin for just your fields and field data. Which approach is best for you depends on your use case -- I think a good question to ask yourself is, do I need these fields (and this data) to persist through a theme change, or is the data so tightly coupled to the theme that they are practically one and the same?
As to your specific code sample, I tried the code you shared in the latest release, WordPress 6.0, and it worked for me as expected, though I did put it inside a function hooked to fm_post_post
. That is:
add_action( 'fm_post_post', function() {
$fm = new Fieldmanager_RichTextArea( array(
'name' => 'richtextfield',
'label' => 'Sample RichText Area',
'editor_settings' => array(
'media_buttons' => false,
),
) );
$fm_cb = new Fieldmanager_Checkbox( array(
'name' => 'checkboxfield',
'label' => 'Sample Checkbox',
'checked_value' => 'yes',
'unchecked_value' => 'no',
) );
$fm->add_meta_box( 'Aimees RichTextArea Demo', array( 'post' ) );
$fm_cb->add_meta_box( 'Custom Checkbox Values', array( 'post' ) );
} );
The action fm_post_post
represents the context where to display the field (fm_post
means the "post" context, and the second post
represents the post type). More can be read about contexts and the post context action here.
When I load up the post edit screen, I see the two fields as expected:
When I enter data in each field and save the post, the data stores as expected, and upon reloading the page, the data loads in as expected.
All that said, I suspect the issue here is a misunderstanding about the post type. In your report, you specifically use the word "page" a few times, which can be a confusing term since some use it to mean the "page"/"screen" they're looking at, or it may be the page post type. If you're loading up the page post type, that would explain why your code isn't working, the second parameter to the add_meta_box()
method is an array of post types for which to add the fields, and in your snippet, only post
is listed. If you change that to array( 'page' )
, your fields would show up on the new/edit screens of the page post type.
Since your code is working as-is for me in the latest version of WordPress, I'm going to close this issue. Please don't let that stop you from asking additional questions in this thread, I'm happy to answer any followup questions you have. Cheers!
from wordpress-fieldmanager.
Hello @mboynes Thank you for this. I now see it with gutenberg on posts and pages. I have to change this to - add_action( 'fm_post_page', function() { }
to get it to show on a page though. Thanks
from wordpress-fieldmanager.
Related Issues (20)
- Conditional visibility but unconditional validation HOT 4
- Hash Fieldmanager_Password values? HOT 2
- UI Issues HOT 3
- Admin menu page stopped working after PHP 8.0 update HOT 2
- Prevent saving values when they are the default value
- Using an image as a Fieldmanager_Radios label HOT 2
- Data not saving if FieldManager enabled in conditional check
- Repeatable fields with nested FM Groups prevent proper saving HOT 1
- Modifying values before save HOT 1
- MenuItem Fields: FM field styling blocks editing the menu item's label
- Custom attachment meta fields not displaying when new image is uploaded HOT 2
- Test suite needs to be updated HOT 1
- TextArea and RichTextArea fields cause a warning in PHP 8.1 HOT 1
- PHP Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated HOT 1
- Resolve PHP Deprecations
- Update class constructor docblocks to support specifying an `array` or a `string` for `$label` HOT 1
- Adding 'required' to a repeater doesn't work HOT 4
- Docs: Where is the list of valid `$attributes` and what they do? HOT 3
- display_if incorrectly hide siblings when matching their `display-src` values
- display_if condition doesn't hide active fields that have their own custom display_if condition
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wordpress-fieldmanager.