Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin tommcfarlin/00-template.php Secret
Created Jul 3, 2019

Embed
What would you like to do?
[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
You can’t perform that action at this time.