Grab variable and use it elsewhere.
-
Primarily PHP, but I am using it in wordpress, and hopefully can get some kind of help with this.
Recently I created a multi-check selection area that auto-populated based on pages listed. (below is the code)
if ( $pages ) { $prop = 'post_title'; $pages = wp_list_pluck( $pages, $prop ); $options[] = array( 'name' => __( 'What Pages to Include?' ), 'class' => 'inner_section_header', 'id' => 'select_pages_to_display', 'options' => $pages, 'std' => '', 'type' => 'multicheck' ); }(thanks to mod keesiemeijer)
But now I wanted to create a container based on the page title from each of those checkboxes (currently set as the label for each option)
The framework sets up each option using this in ‘inc/options-interface.php’ (an outside script):case "multicheck": foreach ($value['options'] as $key => $option) { $checked = ''; $label = $option; $option = preg_replace('/[^a-zA-Z0-9._\-]/', '', strtolower($key)); $id = $option_name . '-' . $value['id'] . '-'. $option; $name = $option_name . '[' . $value['id'] . '][' . $option .']'; if ( isset($val[$option]) ) { $checked = checked($val[$option], 1, false); } $output .= '<input id="' . esc_attr( $id ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $name ) . '" ' . $checked . ' /><label for="' . esc_attr( $id ) . '">' . esc_html( $label ) . '</label>'; } break;This produced a check-menu that looked like this
[]Home
[]Services
[]Portfolio
[]ContactWhich is exactly how I wanted it…it shows all of the pages that I had created.
Basically How would I get the label (or the post title…or the option…whatever works) from the options menu to a variable so that I could use it multiple times through out the loop.
For Example, Say we stored it in a new variable called $title. I would then like to take it and place it as such:echo '<div id="' . $title . '">; $post = get_page_by_title($title); $content = apply_filters('the_content', $post->post_content); echo $content; wp_reset_query(); echo '</div>';This is what I have so far as a function in my functions.php, and I am getting it to display true for each page that is checked in the theme options…but I am having a bit of bad luck getting it to grab the page title for its current item.
function selected_pages_endlyss(){ $multicheck = of_get_option('select_pages_to_display'); foreach ( $multicheck as $current=>$value){ if ( $value == 1 ) { echo 'true'; } else { //silence } unset($current); } }Again, any Help would be greatly appreciated. Thank you.
The topic ‘Grab variable and use it elsewhere.’ is closed to new replies.