-
-
Save tommcfarlin/1276fb31a402b1bc297eaa9be69c71a0 to your computer and use it in GitHub Desktop.
[WordPress] Use Meta Box to Create a FAQ Page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Template Name: FAQs | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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 | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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