GithubHelp home page GithubHelp logo

forwardjumpmarketingllc / genesis-cmb2-meta-boxes Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 0.0 550 KB

Add CMB2 meta boxes and custom fields to Genesis CPT archive and theme settings pages.

PHP 97.62% CSS 2.38%

genesis-cmb2-meta-boxes's Introduction

README

This plugin simplifies adding CMB2 meta boxes to the Genesis Theme Settings and Genesis CPT Archive Settings pages. Group fields are now supported.

Genesis CPT Archive Settings screenshot

Requirements

PHP 5.4+

Installation

Download the zip file and install it using the WordPress plugin installer.

Usage

Meta boxes can be added to the Genesis Theme Settings page or to Genesis CPT Archive Settings pages. Make sure your custom post types have support for 'genesis-cpt-archives-settings'.

  • Use the helper function genesiscmb2_add_theme_settings_box() to add meta boxes to Genesis Theme Settings.
  • Use the helper function genesiscmb2_add_cpt_archive_box() to add meta boxes to Genesis CPT Archive Settings. For example:
<?php

add_action( 'init', 'register_genesis_cpt_settings_metaboxes' );
/**
 * Register Genesis CPT Archive Settings meta boxes.
 */
function register_genesis_cpt_settings_metaboxes() {

	$cpt_config = [
		[
			'metabox' => [
				'title'        => 'Example Genesis CPT Settings CMB2 meta box', // String. Translation function is handled by the class.
				'object_types' => [ 'new-post-type', 'new-post-type-2' ], // Array. CPT slug(s).
			],
			'fields'  => [
				[
					'name' => 'Example field',
					'id'   => 'example_cmb2_field',
					'type' => 'text',
				],
				// Add additional field array(s) here.
			],
		],
		// Add additional meta box array(s) here.
	];
	
	genesiscmb2_add_cpt_archive_box( $cpt_config );

}
  • See example configuration arrays in the config directory. In general, use the same arguments for creating meta boxes and fields as you normally would with CMB2. It is not necessary to include 'id' or 'context' in the 'metabox' array.
  • Retrieve the custom field values using genesis_get_option( $field_id ) and genesis_get_cpt_option( $field_id ).

Credits

Major props to Justin Sternberg for the heavy lifting. This plugin is simply a repackaging of the Justin's example code provided in the CMB2 Snippet Library.

genesis-cmb2-meta-boxes's People

Contributors

timothyjensen avatar

Stargazers

RAVI MISHRA avatar David Decker avatar Stefanie Newton avatar Luís Rodrigues avatar Marcy Diaz avatar  avatar Tom Finley avatar Sérgio Santos avatar

Watchers

James Cloos avatar Josh Fialkoff avatar  avatar

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.