Tickera Backend: How To Add Custom Meta Fields In Tickera - WordPress Event Ticketing (2024)

With this post, we're beginning a series of Tickera Backend blog post. In this series, we will look under the hood and see many possibilities for extending Tickera's functionality. Ready to get your hands dirty? Then roll up your sleeves and dig right in.

Although Tickera offers a very high level of flexibility, we are perfectly aware that every event is different and that there's always that one thing that would make your life easier. This is why Tickera's internals are filled with actions and filters that allow you to customize the plugin to fit your needs. We'll show you how to add meta boxes to Tickera events to start the series. WordPress has functions to add meta boxes to any post type, but we have made it even easier for our users to do it in Tickera. So, you need to hook a function to the filter containing a meta box array and expand it.

To do this, you will have to go through the following steps:

Not sure what is Tickera? Go here to find out!

  1. How to create a plugin to which we will add our code
  2. Hooking into Tickera meta fields array
  3. Display our values on the front end.
How to create the plugin to which we will add our code

To avoid changing any original files in a theme or a plugin, we'll create a custom plugin in which we'll add filters to change the values in the original plugin. Below you'll see the basic layout of a plugin with a few things you might need later on. If you're not sure how to create plugins from scratch, check out Smashing Magazine tutorial. However, if you are not that interested in all the nitty-gritty details just copy the code below and activate the plugin. As another alternative, you can use plugins such as Code Snippets which eliminates the need to create a plugin from scratch and makes it possible to simply add code snippets and activate/deactivate them similarly to what you would do with plugins.

Please note the commented areas in the code below. Those are the places for filters and functions.

/* Plugin Name: Tickera - Custom Meta Fields Plugin URI: http://tickera.com/ Description: Author: Tickera.com Author URI: http://tickera.com/ Version: 1.0 TextDomain: tc Copyright 2022 Tickera (http://tickera.com/) */if (!defined('ABSPATH')) exit; // Exit if accessed directlyif (!class_exists('TC_Custom_Meta')) { class TC_Custom_Meta { var $version = '1.0'; var $title = 'Tickera - Custom Meta'; var $name = 'tc-custom-add-custom-meta'; var $dir_name = 'tc-custom-add-custom-meta'; var $location = 'plugins'; var $plugin_dir = ''; var $plugin_url = ''; function __construct() { $this->init_vars(); <!-- WE'LL USE THIS AREA TO ADD FILTERS --> } function init_vars() { //setup proper directories if (defined('WP_PLUGIN_URL') && defined('WP_PLUGIN_DIR') && file_exists(WP_PLUGIN_DIR . '/' . $this->dir_name . '/' . basename(__FILE__))) { $this->location = 'subfolder-plugins'; $this->plugin_dir = WP_PLUGIN_DIR . '/' . $this->dir_name . '/'; $this->plugin_url = plugins_url('/', __FILE__); } else if (defined('WP_PLUGIN_URL') && defined('WP_PLUGIN_DIR') && file_exists(WP_PLUGIN_DIR . '/' . basename(__FILE__))) { $this->location = 'plugins'; $this->plugin_dir = WP_PLUGIN_DIR . '/'; $this->plugin_url = plugins_url('/', __FILE__); } else if (is_multisite() && defined('WPMU_PLUGIN_URL') && defined('WPMU_PLUGIN_DIR') && file_exists(WPMU_PLUGIN_DIR . '/' . basename(__FILE__))) { $this->location = 'mu-plugins'; $this->plugin_dir = WPMU_PLUGIN_DIR; $this->plugin_url = WPMU_PLUGIN_URL; } else { wp_die(sprintf(__('There was an issue determining where %s is installed. Please reinstall it.', 'tccsv'), $this->title)); } } <!-- WE'LL USE THIS AREA TO ADD FUNCTIONS --> }}
Hooking into the Tickera meta fields array

Meta boxes in Tickera are added by modifying the existing array. So, first, we need to hook into the array via tc_event_fields filter. We'll hook into the filter by using the WordPress function add_filter in our construction method. We will then continue by adding tc_add_meta_fields function. As you can see from the code below, we have one variable passed into the function, which is the array we'll be modifying.

add_filter('tc_event_fields', array(&$this, 'tc_add_meta_fields'), 10, 1);

When adding the filter, we'll add a function that will change Tickera's meta box array. This will be modifying the $default_fields variable, to which we'll add a few more arrays. Below is an example of the first array, followed by comments explaining what each of the fields does.

 $default_fields[] = array( 'field_name' => 'tc_event_room', // The name of the field that will be saved in the database 'field_title' => __('Event Room', 'tc'), // The title of the meta field in the WordPress admin area 'field_type' => 'text', // Type of the input field to show on the front. The following values are accepted: text, textarea, textarea_editor, image. 'field_description' => '', // The description will be visible in the backend 'table_visibility' => false, // If set to 'true' the value of this metabox will be visible in the Tickera > Events table 'post_field_type' => 'post_meta', // You can just leave this field as post meta, we use this as a helper for some other functions 'show_in_post_type' => true);

Let's see now what the example function looks like. In the example below, we have created four new fields: text, textarea, textarea with editor and an image upload box. At the end of the function, we have returned a modified array.

function tc_add_meta_fields($default_fields){ //how to add standard text input meta field $default_fields[] = array( 'field_name' => 'tc_event_room', 'field_title' => __('Event Room', 'tc'), 'field_type' => 'text', 'field_description' => '', 'table_visibility' => true, 'post_field_type' => 'post_meta', 'show_in_post_type' => false); //how to add textarea meta field $default_fields[] = array( 'field_name' => 'tc_additional_info', 'field_title' => __('Additional Info', 'tc'), 'field_type' => 'textarea', 'field_description' => '', 'table_visibility' => true, 'post_field_type' => 'post_meta', 'show_in_post_type' => false); //how to add meta field for textarea with WordPress editor $default_fields[] = array( 'field_name' => 'tc_additional_info_textarea', 'field_title' => __('Additional Info Textarea', 'tc'), 'field_type' => 'textarea_editor', 'field_description' => '', 'table_visibility' => true, 'post_field_type' => 'post_meta', 'show_in_post_type' => false); //How to add additional meta field with an upload button for images. $default_fields[] = array( 'field_name' => 'tc_additional_image', 'field_title' => __('Additional Image', 'tc'), 'field_type' => 'image', 'field_description' => '', 'table_visibility' => true, 'post_field_type' => 'post_meta', 'show_in_post_type' => false); return $default_fields; }

Now that we know how that works let's check out the plugin so far

/* Plugin Name: Tickera - Custom Meta Fields Plugin URI: http://tickera.com/ Description: Author: Tickera.com Author URI: http://tickera.com/ Version: 1.0 TextDomain: tc Copyright 2022 Tickera (http://tickera.com/) */if (!defined('ABSPATH')) exit; // Exit if accessed directlyif (!class_exists('TC_Custom_Meta')) { class TC_Custom_Meta { var $version = '1.0'; var $title = 'Tickera - Custom Meta'; var $name = 'tc-custom-add-custom-meta'; var $dir_name = 'tc-custom-add-custom-meta'; var $location = 'plugins'; var $plugin_dir = ''; var $plugin_url = ''; function __construct() { $this->init_vars(); add_filter('tc_event_fields', array(&$this, 'tc_add_meta_fields'), 10, 1); } function init_vars() { //setup proper directories if (defined('WP_PLUGIN_URL') && defined('WP_PLUGIN_DIR') && file_exists(WP_PLUGIN_DIR . '/' . $this->dir_name . '/' . basename(__FILE__))) { $this->location = 'subfolder-plugins'; $this->plugin_dir = WP_PLUGIN_DIR . '/' . $this->dir_name . '/'; $this->plugin_url = plugins_url('/', __FILE__); } else if (defined('WP_PLUGIN_URL') && defined('WP_PLUGIN_DIR') && file_exists(WP_PLUGIN_DIR . '/' . basename(__FILE__))) { $this->location = 'plugins'; $this->plugin_dir = WP_PLUGIN_DIR . '/'; $this->plugin_url = plugins_url('/', __FILE__); } else if (is_multisite() && defined('WPMU_PLUGIN_URL') && defined('WPMU_PLUGIN_DIR') && file_exists(WPMU_PLUGIN_DIR . '/' . basename(__FILE__))) { $this->location = 'mu-plugins'; $this->plugin_dir = WPMU_PLUGIN_DIR; $this->plugin_url = WPMU_PLUGIN_URL; } else { wp_die(sprintf(__('There was an issue determining where %s is installed. Please reinstall it.', 'tccsv'), $this->title)); } } function tc_add_meta_fields($default_fields){ $default_fields[] = array( 'field_name' => 'tc_event_room', 'field_title' => __('Event Room', 'tc'), 'field_type' => 'text', 'field_description' => '', 'table_visibility' => false, 'post_field_type' => 'post_meta', 'show_in_post_type' => true); $default_fields[] = array( 'field_name' => 'tc_additional_info', 'field_title' => __('Additional Info', 'tc'), 'field_type' => 'textarea', 'field_description' => '', 'table_visibility' => false, 'post_field_type' => 'post_meta', 'show_in_post_type' => false); $default_fields[] = array( 'field_name' => 'tc_additional_info_textarea', 'field_title' => __('Additional Info Textarea', 'tc'), 'field_type' => 'textarea_editor', 'field_description' => '', 'table_visibility' => true, 'post_field_type' => 'post_meta', 'show_in_post_type' => false); $default_fields[] = array( 'field_name' => 'tc_additional_image', 'field_title' => __('Additional Image', 'tc'), 'field_type' => 'image', 'field_description' => '', 'table_visibility' => true, 'post_field_type' => 'post_meta', 'show_in_post_type' => false); return $default_fields; } }}$tc_custom_meta = new TC_Custom_Meta();

Now that we added meta fields, we need a way to display them somehow. The easiest way would be to just hook into the the_contentfilter with the line below added to the construct.

add_filter('the_content', array(&$this, 'tc_add_tickera_custom_meta'), 10, 1);

Afterward, we'll add a function that matches the one from the filter and we will be passing the $content variable that we will be altering. We will be using the standard WordPress function get_post_meta to get the values from our meta fields in this function. Please note that all the fields have the same names as their field names in the array except the image field type. Add file_url at the end of the name for the image field type, as shown in the example below, to get the field value.

<?phpfunction tc_add_tickera_custom_meta( $content ) { $tc_event_room = get_post_meta(get_the_id(), 'tc_event_room', true); $tc_additional_info = get_post_meta(get_the_id(), 'tc_additional_info', true); $tc_additional_info_textarea = get_post_meta(get_the_id(), 'tc_additional_info_textarea', true); $tc_additional_image = get_post_meta(get_the_id(), 'tc_additional_image_file_url', true); // Check if we're inside the main loop in a single Post. if ( is_singular() && get_post_type(get_the_ID()) == 'tc_events' ) { return '<strong>Event Room: </strong>'.$tc_event_room . '<br /> ' . '<strong>Additional Info: </strong>' .$tc_additional_info . '<br />' . '<strong>Additional Info Textarea: </strong>' . $tc_additional_info_textarea . '<br />' . '<strong>Additional Image: </strong>' . $tc_additional_image . '<br />' . $content; } return $content; } ?>

Now that we have added this function, head over to Tickera > Events. The fields we have added should be displayed. Try entering some values to these fields and then save changes to check if the values are saving properly. After that, navigate to the event page and check if these values are showing properly on the front end.

As a reference, below is complete plugin that we have just created.

<?php/* Plugin Name: Tickera - Custom Meta Fields Plugin URI: http://tickera.com/ Description: Author: Tickera.com Author URI: http://tickera.com/ Version: 1.0 TextDomain: tc Copyright 2022 Tickera (http://tickera.com/) */if (!defined('ABSPATH')) exit; // Exit if accessed directlyif (!class_exists('TC_Custom_Meta')) { class TC_Custom_Meta { var $version = '1.0'; var $title = 'Tickera - Custom Meta'; var $name = 'tc-custom-add-custom-meta'; var $dir_name = 'tc-custom-add-custom-meta'; var $location = 'plugins'; var $plugin_dir = ''; var $plugin_url = ''; function __construct() { $this->init_vars(); add_filter('tc_event_fields', array(&$this, 'tc_add_meta_fields'), 10, 1); add_filter('the_content', array(&$this, 'tc_add_tickera_custom_meta'), 10, 1); } function init_vars() { //setup proper directories if (defined('WP_PLUGIN_URL') && defined('WP_PLUGIN_DIR') && file_exists(WP_PLUGIN_DIR . '/' . $this->dir_name . '/' . basename(__FILE__))) { $this->location = 'subfolder-plugins'; $this->plugin_dir = WP_PLUGIN_DIR . '/' . $this->dir_name . '/'; $this->plugin_url = plugins_url('/', __FILE__); } else if (defined('WP_PLUGIN_URL') && defined('WP_PLUGIN_DIR') && file_exists(WP_PLUGIN_DIR . '/' . basename(__FILE__))) { $this->location = 'plugins'; $this->plugin_dir = WP_PLUGIN_DIR . '/'; $this->plugin_url = plugins_url('/', __FILE__); } else if (is_multisite() && defined('WPMU_PLUGIN_URL') && defined('WPMU_PLUGIN_DIR') && file_exists(WPMU_PLUGIN_DIR . '/' . basename(__FILE__))) { $this->location = 'mu-plugins'; $this->plugin_dir = WPMU_PLUGIN_DIR; $this->plugin_url = WPMU_PLUGIN_URL; } else { wp_die(sprintf(__('There was an issue determining where %s is installed. Please reinstall it.', 'tccsv'), $this->title)); } } function tc_add_meta_fields($default_fields){ $default_fields[] = array( 'field_name' => 'tc_event_room', 'field_title' => __('Event Room', 'tc'), 'field_type' => 'text', 'field_description' => '', 'table_visibility' => false, 'post_field_type' => 'post_meta', 'show_in_post_type' => true); $default_fields[] = array( 'field_name' => 'tc_additional_info', 'field_title' => __('Additional Info', 'tc'), 'field_type' => 'textarea', 'field_description' => '', 'table_visibility' => false, 'post_field_type' => 'post_meta', 'show_in_post_type' => false); $default_fields[] = array( 'field_name' => 'tc_additional_info_textarea', 'field_title' => __('Additional Info Textarea', 'tc'), 'field_type' => 'textarea_editor', 'field_description' => '', 'table_visibility' => true, 'post_field_type' => 'post_meta', 'show_in_post_type' => false); $default_fields[] = array( 'field_name' => 'tc_additional_image', 'field_title' => __('Additional Image', 'tc'), 'field_type' => 'image', 'field_description' => '', 'table_visibility' => true, 'post_field_type' => 'post_meta', 'show_in_post_type' => false); $default_fields[] = array( 'field_name' => 'tc_additional_function', 'field_title' => __('Additional Function', 'tc'), 'field_type' => 'function', 'function' => 'tc_additional_function', 'field_description' => '', 'table_visibility' => true, 'post_field_type' => 'post_meta', 'show_in_post_type' => false); return $default_fields; } function tc_add_tickera_custom_meta( $content ) { $tc_event_room = get_post_meta(get_the_id(), 'tc_event_room', true); $tc_additional_info = get_post_meta(get_the_id(), 'tc_additional_info', true); $tc_additional_info_textarea = get_post_meta(get_the_id(), 'tc_additional_info_textarea', true); $tc_additional_image = get_post_meta(get_the_id(), 'tc_additional_image_file_url', true); // Check if we're inside the main loop in a single Post. if ( is_singular() && get_post_type(get_the_ID()) == 'tc_events' ) { return '<strong>Event Room: </strong>'.$tc_event_room . '<br />' . '<strong>Additional Info: </strong>' .$tc_additional_info . '<br />' . '<strong>Additional Info Textarea: </strong>' . $tc_additional_info_textarea . '<br />;' . '<strong>Additional Image: </strong>' . $tc_additional_image . '<br />' . $content; } return $content; } }}$tc_custom_meta = new TC_Custom_Meta();?>

Got any questions, ideas or suggestions? Shoot us an email to info@tickera.com and we're gladly hear all about it.

Tickera Backend: How To Add Custom Meta Fields In Tickera - WordPress Event Ticketing (2024)

FAQs

How do I add a custom meta field in WordPress? ›

Create a custom metadata box in the post or page editor
  1. In the Boxes panel, check Custom Fields.
  2. Scroll down, and you'll see a new Custom Fields panel available.
  3. Click the Name dropdown menu to edit an existing metadata field in your theme.
  4. Alternatively, click the Enter New button to create a new metadata entry.
Jun 10, 2021

How to add custom meta box in WordPress programmatically? ›

Step One: Create and Put Heading into Plugin

If you go to the wp-content folder, you will see a plugins folder. Make a new folder called custom-post-meta-box with a custom-post-meta-box. php file in it. This is the file you will be working from.

How do I add a custom field to WordPress? ›

Go to the Toolset → Dashboard page and click the Add custom fields in the row of the post type you want to add custom fields to. Click to select the type of the custom field you want to create first. In the dialog that appears, type in the name of your field. Slug is created automatically.

How to create custom fields in WordPress without plugins? ›

First, click the three dots in the upper right corner of the post editor, and then click Preferences from the menu that appears. Next, click Panels, and then toggle on the Custom fields selector. Finally, click Show & Reload Page to proceed.

How to add custom meta boxes in WordPress posts and post types? ›

To add a Meta Box to a custom post type in WordPress, you need to use the 'add_meta_box()' function. This function allows you to specify the Meta Box ID, title, callback function, post type, context, and priority. The callback function is used to output the content of the Meta Box.

How do I manually add meta description in WordPress? ›

Navigate to the SEO tab when editing a post or page. Add your desired meta title and description in the Snippet Editor. Save your changes or publish the post.

How do I add custom fields to metadata? ›

To add a new metadata type with custom fields

From the Info window, click Edit meta-data types, and click the Create button at the bottom of the list of existing types. Enter the name for the metadata type, and then enter the individual fields that will make up this type.

How do I add meta data to WordPress? ›

To add meta tags and a meta description and work on the overall appearance of your website, click on SEO > Search Appearance. This will take you to one of the setting's pages for Yoast where you will be able to tinker and add whatever you want.

How do you add a meta field? ›

Step one: Create a metafield definition
  1. From your Shopify admin, go to Settings > Custom data.
  2. In the Metafields section, click Product metafields.
  3. Click Add definition.
  4. Name your metafield definition Care guide and click the standard metafield definition that is displayed. ...
  5. Click Save.

Top Articles
Quick and Easy Strawberry Shortcake Recipe
Easy Banana Bread Recipe (Top-Rated) - Celebrating Sweets
Spasa Parish
Rentals for rent in Maastricht
159R Bus Schedule Pdf
Sallisaw Bin Store
Black Adam Showtimes Near Maya Cinemas Delano
Espn Transfer Portal Basketball
Pollen Levels Richmond
11 Best Sites Like The Chive For Funny Pictures and Memes
Things to do in Wichita Falls on weekends 12-15 September
Craigslist Pets Huntsville Alabama
Paulette Goddard | American Actress, Modern Times, Charlie Chaplin
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
What's the Difference Between Halal and Haram Meat & Food?
R/Skinwalker
Rugged Gentleman Barber Shop Martinsburg Wv
Jennifer Lenzini Leaving Ktiv
Justified - Streams, Episodenguide und News zur Serie
Epay. Medstarhealth.org
Olde Kegg Bar & Grill Portage Menu
Cubilabras
Half Inning In Which The Home Team Bats Crossword
Amazing Lash Bay Colony
Juego Friv Poki
Dirt Devil Ud70181 Parts Diagram
Truist Bank Open Saturday
Water Leaks in Your Car When It Rains? Common Causes & Fixes
What’s Closing at Disney World? A Complete Guide
New from Simply So Good - Cherry Apricot Slab Pie
Drys Pharmacy
Ohio State Football Wiki
Find Words Containing Specific Letters | WordFinder®
FirstLight Power to Acquire Leading Canadian Renewable Operator and Developer Hydromega Services Inc. - FirstLight
Webmail.unt.edu
2024-25 ITH Season Preview: USC Trojans
Metro By T Mobile Sign In
Restored Republic December 1 2022
12 30 Pacific Time
Jami Lafay Gofundme
Greenbrier Bunker Tour Coupon
No Compromise in Maneuverability and Effectiveness
Black Adam Showtimes Near Cinemark Texarkana 14
Teamnet O'reilly Login
U-Haul Hitch Installation / Trailer Hitches for Towing (UPDATED) | RV and Playa
Minute Clinic Schedule 360
Tyson Foods W2 Online
Bella Poarch Husband: A Deep Dive Into Her Relationship And Personal Life
Best Drugstore Bronzers
Function Calculator - eMathHelp
Craigslist Antelope Valley General For Sale
Latest Posts
Article information

Author: Velia Krajcik

Last Updated:

Views: 5853

Rating: 4.3 / 5 (74 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.