1

i'm getting the following error on the homepage of a site I'm working on:

'Notice: Undefined index: active in /home/sites/tradehelp.co.uk/public_html/testweb/wp-content/themes/tradehelp/page.php on line 7'

I have downloaded the specified file but everything seems to be OK to me so can't figure out what it is. The page.php code is as follows:

<?php get_header(); ?>

    <?php $meta = get_post_meta($post->ID, 'clicky_meta', true); ?>

    <?php foreach($meta['page_sections'] as $section => $values) { ?>

        <?php if ($values['active']) { ?>
            <?php get_template_part('includes/blocks/section', $section); ?>
        <?php } ?>

    <?php } ?>

<?php get_footer(); ?>
                <?php
                    $page_sections = array(
                        'content_1'         => array('label' => 'Content Section 1'),
                        'icon_grid'         => array('label' => 'Icons Grid'),
                        'app_banner'        => array('label' => 'App Banner'),
                        'content_2'         => array('label' => 'Content Section 2'),
                        'testimonials'      => array('label' => 'Testimonials'),
                        'featured_video'    => array('label' => 'Featured Video'),
                        'content_3'         => array('label' => 'Content Section 3'),
                        'partners'          => array('label' => 'Partners'),
                        'partners_small'    => array('label' => 'Partners Small'),
                        'promotion'         => array('label' => 'Promotional Area'),
                        'faqs'              => array('label' => 'FAQs'),
                        'image'             => array('label' => 'Image'),
                        'finance_calc'      => array('label' => 'Finance Calculator'),
                        'case_studies'      => array('label' => 'Case Studies'),
                        'benefits'          => array('label' => 'Benefits'),
                        'statistics'        => array('label' => 'Statistics'),
                        'latest_news'       => array('label' => 'Latest News'),
                        'accreditations'    => array('label' => 'Accreditations'),
                        'enquiry_form'      => array('label' => 'Enquiry Form')
                    );
                ?>
                <?php custom_sortable_field('page_sections', false, $page_sections); ?>

Thanks in advance

Lee Lawton
  • 11
  • 3
  • Show us the contents of `$meta['page_sections']` after you set `$meta`. – GrumpyCrouton Aug 26 '20 at 19:31
  • Also, PHP can be multi-line. There is no need to use `` on every single line, that makes the code look so unorganized and severely harms readability. You just need one `` at the end. – GrumpyCrouton Aug 26 '20 at 19:41
  • Thanks, have added this now – Lee Lawton Aug 26 '20 at 19:47
  • That is not the value of `$meta['page_sections']` after setting `$meta` in your first script. I don't know what the code is that you just added, but it also doesn't match the format you seem to be expecting. – GrumpyCrouton Aug 26 '20 at 19:49
  • You don't have "active" key at the $page_sections. You should add it to $page_sections, for example: array('label' => 'Content Section 1', 'active' => true), – Reza Fathi Aug 26 '20 at 20:21

0 Answers0