Match checkbox data with page title to show certain items

I managed to figure it out myself reading around, solved it with this:

   <div id="grid">
<?php $args = array(
    'depth'        => 0,
    'child_of'     => 411 );
$pages = get_pages(array('child_of'));
$grid_title = $post->post_title;

foreach($pages as $post)
{
setup_postdata($post);
$fields = get_fields();?>

<?php if($fields->company_name != "") : ?>
<!-- Any new tags will need to be added below -->
<?php if((in_array("Branding", get_field('categories')) && $grid_title == "Branding") || (in_array("Creative", get_field('categories')) && $grid_title == "Creative") || (in_array("Development", get_field('categories')) && $grid_title == "Development") || (in_array("Exhibition", get_field('categories')) && $grid_title == "Exhibition") || (in_array("Packaging", get_field('categories')) && $grid_title == "Packaging") || (in_array("Print", get_field('categories')) && $grid_title == "Print") || (in_array("SEO", get_field('categories')) && $grid_title == "SEO") || (in_array("Usability", get_field('categories')) && $grid_title == "Usability") || (in_array("Web", get_field('categories')) && $grid_title == "Web") || (in_array("Campaign", get_field('categories')) && $grid_title == "Campaign") || (in_array("Copywriting", get_field('categories')) && $grid_title == "Copywriting") || (in_array("Feasibility", get_field('categories')) && $grid_title == "Feasibility") || (in_array("Research", get_field('categories')) && $grid_title == "Research") || (in_array("Social Media", get_field('categories')) && $grid_title == "Social Media")){
     echo "
        <div class=\"grid-box\" onclick=\"location.href="" . get_page_link($post->ID) ."";\" style=\"cursor: pointer;\">
        <div class=\"phase-1\">
           <img class=\"grid-image\" src=\"" . $fields->thumb_image . "\" alt=\"" . $fields->company_name ."\" height=\"152\" width=\"210\" />
           <div class=\"grid-heading\">
                <h2>". $fields->company_name ."</h2>
                <h3>" . implode(', ',get_field('categories')) ."</h3>
            </div> 
        </div>
        <div class=\"phase-2\">
            <div class=\"grid-info\">
                <h4>". $fields->project_name ."</h4>
                <p>". $fields->description ."</p>
            </div>
            <div class=\"grid-heading-hover\">
                <h2>". $fields->company_name ."</h2>
                <h3>". implode(', ',get_field('categories')) ."</h3>
            </div> 
        </div>
    </div>
     ";
}
else {
    echo "  <div class=\"grid-box\" onclick=\"location.href="" . get_page_link($post->ID) ."";\" style=\"cursor: pointer;\">
        <div class=\"phase-1\">
           <img class=\"grid-image\" src=\"" . $fields->thumb_image . "\" alt=\"" . $fields->company_name ."\" height=\"152\" width=\"210\" />
           <div class=\"grid-heading\">
                <h2>". $fields->company_name ."</h2>
                <h3>" . implode(', ',get_field('categories')) ."</h3>
            </div> 
        </div>
        <div class=\"phase-2\">
            <div class=\"grid-info\">
                <h4>". $fields->project_name ."</h4>
                <p>". $fields->description ."</p>
            </div>
            <div class=\"grid-heading-hover\">
                <h2>". $fields->company_name ."</h2>
                <h3>". implode(', ',get_field('categories')) ."</h3>
            </div> 
        </div>
    </div>";
}

else : ?>
<?php endif; ?>    

<?php
}

wp_reset_query();
?>        
</div>

Leave a Comment