Git Product home page Git Product logo

Comments (2)

mboynes avatar mboynes commented on September 26, 2024

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:

Screen Shot 2022-05-26 at 11 27 55 AM

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.

aimeetacchi avatar aimeetacchi commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.