Skip to content

Adding Meta Boxes

Paul Ryley edited this page May 16, 2017 · 3 revisions

The way you enter Meta-boxes in Pollux is almost identical to the meta-box arrays you create with the Meta Box plugin except for the following few changes which you must be aware of:

  1. In the Meta Box plugin you enter an "ID" key inside the meta-box arrays and in each meta-box field array. In Pollux, you enter the "ID" as the array key for each meta-box and meta-box field.

  2. Unlike the Meta Box plugin, all meta-boxes must have a unique ID, and all meta-box fields within a meta-box must also have a unique ID.

  3. Please see Meta Box Conditions for information on how to use the "condition" and "depends" keys

Please see Meta Box plugin (getting started) example for more information about available options for both meta-boxes and meta-box fields.

Example configuration for the "Post Type Meta Boxes" field

You may copy and paste the following into the Post Type Meta Boxes field in the Pollux settings.

# This key is the meta-box ID
front_page:

  # This key defines which post types to attach this meta-box to.
  # Value can either be a single post type, or a list of post types.
  post_types: page

  # This key is the Meta Box title
  title: Front Page Options

  # This key defines one or more Meta Box conditions
  condition:
    is_front_page: true

  # This key defines the meta-box fields
  fields:

    # This key is the meta-box field ID
    media:

      # This key is the meta-box field type.
      # https://metabox.io/docs/define-fields/#section-list-of-supported-field-type
      type: image_advanced

gallery_options:
  post_types: page
  title: Gallery Options
  condition:
    is_page_template: template-gallery.php
  fields:
    gallery:
      type: post
      name: Gallery
      placeholder: Select a gallery
      field_type: select
      post_type: gallery
    images_per_page:
      # This key sets the visibility depending on whether or not another field has a value
      depends: pagination
      type: number
      name: Images Per Page
      size: 4
    lazyload:
      depends: gallery
      type: checkbox
      name: Lazyload Images?
    pagination:
      depends: gallery
      type: checkbox
      name: Use Pagination?
gallery_media:
  post_types:
    - gallery
  title: Gallery Media
  fields:
    media:
      type: image_advanced