GithubHelp home page GithubHelp logo

florianbeck / cmb2-field-type-tags Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 4.0 101 KB

WordPress-Tags-like field type for Custom Metaboxes and Fields for WordPress using CMB2.

PHP 22.30% CSS 8.80% JavaScript 68.90%

cmb2-field-type-tags's Introduction

CMB2 Field Type: Tags

Contributors: florianbeck
License: GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)

WordPress-Tags-like field type for Custom Metaboxes and Fields for WordPress using CMB2.

Not Maintained

Description

WordPress-Tags-like field type for CMB2. Based on WordPress Tags-Like Meta Box.

This plugin gives you two CMB2 field types:

  1. The tags field acts like WordPress's default tags list.
  2. The tags_sortablefield acts like WordPress's default tags list as well, but adds sorting.

The Entrys will be saved as single string separated with semicolons.

Note: This field may not support repetition, repeatable fields/groups is untested.

Installation

You can install this field type as you would a WordPress plugin:

  1. Download the plugin.
  2. Place the plugin folder in your wp-content/plugins/ directory.
  3. Activate the plugin in the Plugin dashboard.

Alternatively, you can place the plugin folder within your theme/plugin. After you call CMB2, add another line to include the cmb2-field-tags.php file. Something like:

require_once 'cmb2-field-type-tags/cmb2-field-type-tags.php';

Usage

See CMB2's Wiki for general information and a basic example of how to create a metabox with CMB2.

Initialize the fields

  1. Create a metabox.
  2. Add the custom field by calling the add_field-function of the metabox:

tags โ€” WordPress-Tags-like input field. Example:

$cmb->add_field( array(
	'name' => __( 'Related Publications', 'textdomain' ),
	'desc' => __( 'Add or remove BibTeX-keys.', 'textdomain' ),
	'id'   => $prefix . 'related_publications',
	'type' => 'tags',
) );

tags_sortable โ€” WordPress-Tags-like input field that allows sorting. Example:

$cmb->add_field( array(
	'name' => __( 'Tasks', 'textdomain' ),
	'desc' => __( 'Add or remove tasks, drag and drop to sort.', 'textdomain' ),
	'id'   => $prefix . 'tasks',
	'type' => 'tags_sortable',
) );

Show in the frontent

You can get the entrys by get_post_meta( get_the_ID(), 'prefix_tasks', true ) );
The entrys are stored as one single string separated with semicolons. Example:
idea;concept designer;system designer;programmer;deploying artist

Generate an array. Example:

$tasks = explode( ';', get_post_meta( get_the_ID(), 'prefix_tasks', true ) );
foreach ( $tasks as $task ) {
    printf('<li>%s</li>', $task);
}

Replace separator. Example:

$tasks = str_replace(';', ', ', get_post_meta( get_the_ID(), 'prefix_tasks', true ) );
echo $tasks;

Screenshots

Tags box

Adding entry in tags box: Adding entry in tags box

Deleting entry in tags box: Deleting entry in tags box

Tags box (sortable)

Adding entry in tags_sortable box: Adding entry in tags_sortable box

Sorting entry in tags_sortable box: Deleting entry in tags_sortablebox

cmb2-field-type-tags's People

Contributors

florianbeck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cmb2-field-type-tags's Issues

repeated value

I use this plugin in Group field type, But when I store data in tag type, I see my stored data in the next tag-type too!

latest demo of cmb2 : https://github.com/CMB2/CMB2-Snippet-Library/blob/master/options-and-settings-pages/theme-options-cmb.php

I also use latest version of cmb2, But I cant understand whats your mean about $prefix in this example :

$cmb->add_field( array(
'name' => __( 'Related Publications', 'textdomain' ),
'desc' => __( 'Add or remove BibTeX-keys.', 'textdomain' ),
'id' => $prefix . 'related_publications',
'type' => 'tags',
) );

worspress?

in the project title you have worspress
mfg,
mike

doesn't work with theme options snippet

Hi
I want to use this with a hacked version of the theme option snippet used for a plugin options page.

My other CMB2 fields and also the multcheck_posttype field are working fine.

Any ideas?

Cheers
Mike

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.