Comments (2)
I was able to make some fields for a metabox using the functions in this plugin.
This code in the $this->meta_box_content() function is looking for a filter named $post->post_type . '_custom_fields'
$fields = apply_filters( $post->post_type . '_custom_fields', array(), $post->post_type );
For a custom post type "listing" the user will have to create a filter called
listing_custom_fields
And that filter needs to have a function added to it to create the custom data entry fields. In this example, I added a function called
add_listing_custom_fields
Here is the all the code in one place, which I put into my copy of wordpress-plugin-template.php
// Create a custom post type
WordPress_Plugin_Template()->register_post_type( 'listing', __( 'Listings', '' ), __( 'Listing', 'wordpress-plugin-template' ) );
// Add a metabox to page and listing post types
add_action( 'add_meta_boxes', 'add_meta_box_1');
function add_meta_box_1(){
WordPress_Plugin_Template()->admin->add_meta_box ('metabox_1',__( 'Metabox 1', 'wordpress-plugin-template' ), array("listing",'page'));
}
// Add custom post fieds to metabox_1
function add_listing_custom_fields(){
$fields=array();
$fields[]=array(
"metabox"=>array(
'name'=>"metabox_1"
),
'id'=>"metabox_1_field_1",
'label'=>"Metabox_1_field_1 Label",
'type'=>'text',
'placeholder'=>"the placeholder",
'description'=>"the description"
);
return $fields;
}
// Add the function to the filter.
add_filter("listing_custom_fields", "add_listing_custom_fields");
from wordpress-plugin-template.
I will try to explain the problem further.
If I put this code in /WordPress-Plugin-Template|wordpress-plugin-template.php
// This creates a custom post type "listing"
WordPress_Plugin_Template()->register_post_type( 'listing', __( 'Listings', '' ), __( 'Listing', 'wordpress-plugin-template' ) );
// This adds a metabox to "listing" and "page" post types.
add_action( 'add_meta_boxes', 'add_meta_box_1');
function add_meta_box_1(){
WordPress_Plugin_Template()->admin->add_meta_box ('metabox_1',__( 'Metabox 1', 'wordpress-plugin-template' ), array("listing",'page'));
}
When WordPress_Plugin_Template()->admin->add_meta_box is run, it calls this function for each post type.
add_meta_box( $id, $title, array( $this, 'meta_box_content' ), $post_type, $context, $priority, $callback_args );
This in turn calls $this->meta_box_content which gets the fields for the metaboxes like this:
$fields = apply_filters( $post->post_type . '_custom_fields', array(), $post->post_type );
This is what I totally do not understand. How can I add the fields so that this line of code can get the fields for the metabox? Where are these fields supposed to come from?
from wordpress-plugin-template.
Related Issues (20)
- Register Setting validation not working. HOT 1
- Duplicated update_post_meta in multi-instances of the boilerplate
- Quick edit clearing the meta data of registered metaboxes
- The future of this plugin template repository. HOT 1
- build-plugin script should rename settings base prefix HOT 1
- Installer error: "fatal: Too many arguments." HOT 2
- PHP-codesniffer says: use a nonce on the tabbed settings. HOT 2
- Implement namespaces and autoloading
- Fatal Error: Cannot access private property $admin in class-wordpress-plugin-template-settings.php on line 367 HOT 1
- Sanitize tabs HOT 3
- How to display html on external pages of the site? HOT 2
- How to display html on external pages of the site? HOT 5
- Options prefix should be set at install script HOT 1
- Dynamically populate multi-select? HOT 1
- Test develop branch HOT 13
- Wordpress guidelines compliance issues HOT 2
- Allow people to use this repo as a template repository HOT 3
- Settings
- Custom Post Type $args, Taxonomy $args HOT 1
- Validation callback example
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-plugin-template.