1

I've used the wordpress plugin - advanced custom field and would like to show an array of a child, here's my code:

I'm using this code to show the custom fields data from a specific page ID's children:

<?php $args = array(
    'depth'        => 0,
    'child_of'     => 411 );
$pages = get_pages(array('child_of'));

foreach($pages as $post)
{
setup_postdata($post);
$fields = get_fields();
if($fields->company_name != "") : ?>
   <h2><?php echo $fields->company_name; ?></h2>
<?php else : ?>
<?php endif; ?> 
<?php
}

wp_reset_query();
?>

This is the code I'm using to show the checkbox data of the page itself (i.e it's not a parent/child):

<?php $catNames = array( 'branding','creative','development','exhibition','packaging','print','seo','social_media','usability','web','advertising','campaign','content','feasibility','publishing','research','strategy');

    foreach($catNames as $name){
        if(in_array($name, get_field('categories') )){
            echo '<a href="/tags/design/'.$name.'" title="'.$name.'">'.ucwords($name).'</a>';       
        }
    }
?> 

I want to combine the two together so underneath the H2 tag in the first code box I want to show the checkbox data of the child, how can this be done?

UPDATE: When I add the checkbox code to the child code, I can't get the data to display, it's either blank or has an error.

This is the page I'm working on. The first thumbnail has been hardcoded, the second and third thumbnails should pick up the tags with the code above but it doesn't.

1

This will show the checkboxes that have been ticked (much simpler!!):

                    <?php
$categories = get_field('categories');
$elements = array();
foreach($categories as $category) {
    //do something
    $elements[] = '<a href="/tags/design/' . strtolower($category) . '" title="' . $category . '">' . $category .'</a>';
}
echo implode(',', $elements);
?>
  • I don't think you should ask that question here. This is answer. Just leave your answer part, and ask the question separately - as you did – Lea Cohen May 19 '11 at 7:07
0

Try this code:

<?php $args = array(
    'depth'        => 0,
    'child_of'     => 411 );
$pages = get_pages(array('child_of'));
$catNames = array( 'branding','creative','development','exhibition','packaging','print','seo','social_media','usability','web','advertising','campaign','content','feasibility','publishing','research','strategy');
foreach($pages as $post){
    setup_postdata($post);
    $company = get_field('company_name',$post->ID);
    if( $company != "") {
       echo '<h2>'.$company.'</h2>';
       foreach($catNames as $key => $val){
            if(in_array($val, get_field('categories',$post->ID) )){
                echo '<a href="/tags/design/'.$val.'" title="'.$val.'">'.ucwords($val).'</a>';       
            }
        }
    }
}
wp_reset_query();
?>
  • Can I put this on any page and it will show the children of page 411 and show their checkboxes (in theory!)? Also, I had only left the company variable in as there are about 8-10 different variables, could I just copy how you've done it for the company one? – Rob May 17 '11 at 21:07
  • Just tried the code, the checkbox answer don't appear. I don't think I explained well enough - it should be grabbing the checkboxes of the children, just like the company variable. Doesn't $post->ID grab the parent? – Rob May 17 '11 at 21:23
  • no the $post->ID is any child since you have setup_postdata($post); – Bainternet May 18 '11 at 4:55
  • Oh ok, it still doesn't work though. – Rob May 18 '11 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.