Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created July 3, 2019 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/1276fb31a402b1bc297eaa9be69c71a0 to your computer and use it in GitHub Desktop.
Save tommcfarlin/1276fb31a402b1bc297eaa9be69c71a0 to your computer and use it in GitHub Desktop.
[WordPress] Use Meta Box to Create a FAQ Page
<?php
/**
* Template Name: FAQs
*/
<?php
add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
function your_prefix_register_meta_boxes( $meta_boxes ) {
$meta_boxes[] = array (
'title' => 'FAQs Page',
'id' => 'faqs-page',
'post_types' => array(
0 => 'page',
),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array (
'id' => 'faq_tab',
'type' => 'group',
'name' => 'Tab',
'fields' => array(
array (
'id' => 'tab_name',
'type' => 'text',
'name' => 'Tab Name',
),
array (
'id' => 'q_and_a',
'type' => 'group',
'name' => 'Q & A',
'fields' => array(
array (
'id' => 'question',
'type' => 'text',
'name' => 'Question',
),
array (
'id' => 'answer',
'type' => 'textarea',
'name' => 'Answer',
),
),
'clone' => 1,
'default_state' => 'expanded',
'add_button' => 'Add More Questions',
),
),
'clone' => 1,
'default_state' => 'expanded',
'add_button' => 'Add New Tab',
),
),
'h' => 'a',
'b' => 'c',
'include' => array(
'relation' => 'OR',
'ID' => 6,
'template' => array(
0 => 'page-faqs.php',
),
'category' => array(
0 => 1,
),
),
);
return $meta_boxes;
}
<?php
$group_values = rwmb_meta( 'group_id' );
if ( ! empty( $group_values ) ) {
foreach ( $group_values as $group_value ) {
$value = isset( $group_value[$sub_field_key] ) ? $group_value[$sub_field_key] : '';
echo $value; // Display sub-field value
}
}
<?php
$group_values = rwmb_meta( 'group_id' );
if ( ! empty( $group_values ) ) {
foreach ( $group_values as $group_value ) {
$value = isset( $group_value[$sub_field_key] ) ? $group_value[$sub_field_key] : '';
$group_childs = isset( $group_value[$gr_childs] ) ? $group_value[$gr_childs] : '';
foreach ( $group_childs as $group_child ) {
$val_child = isset( $group_child[$child_key] ) ? $group_child[$child_key] : '';
echo $val_child;
}
echo $value;
}
}
<script src="https://gist.github.com/kutoi94/a8dcdaab6ce9613d3588eea7ae8e6506.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment