wordpress - Get a ACF field using get_pages() -
i'm displaying list of sibling pages using below code. retrieving page title , link. need grab custom field called excerpt
, output each sibling item. how do using get_pages
? var_dump i'm using grabbing current pages excerpt, incorrect.
<?php global $post; if ( is_page() && $post->post_parent ) { $children = get_pages('child_of='.$post->id); $parent = $post->post_parent; $our_pages = get_pages('child_of='.$parent.'&exclude='.$post->id); $ex = get_field('excerpt', $our_pages); if (!empty($our_pages)): foreach ($our_pages $key => $page_item): <a href="<?php echo esc_url(get_permalink($page_item->id)); ?>" title="<?php the_title(); ?>"> <?php echo $page_item->post_title ; ?> <?php var_dump($ex) ?> <?php endforeach; endif; }
update
ok have put in <?php print_r($page_item); ?>
suggested , has returned following:
i don't see of acf fields here, how retrieve those? next steps?
you full code below:
<?php global $post; if ( is_page() && $post->post_parent ) { $children = get_pages('child_of='.$post->id); $parent = $post->post_parent; $our_pages = get_pages('child_of='.$parent.'&exclude='.$post->id); $ex = get_field('excerpt', $our_pages); if (!empty($our_pages)): foreach ($our_pages $key => $page_item): <a href="<?php echo esc_url(get_permalink($page_item->id)); ?>" title="<?php the_title(); ?>"> <?php echo $page_item->post_title ; ?> <?php echo get_post_meta( $page_item->id, 'excerpt', true); ?> <?php endforeach; endif; }
if didn't data above change custom filed name other name , try.
Comments
Post a Comment