I am trying to pull in a custom field vales for each page while using wp_list_pages. For example I want to list out each portfolio item in my sidebar but also show why type of work it is by pulling in a custom field value so it would look like this:
- Portfolio Item 1 Type: Web Design
- Portfolio Item 2 Type: Web Development
Here is the code I am using to pull in custom post types and this works perfectly, I just have no idea how to have it pull custom field values as well:
function wp_list_post_types( $args ) {
$defaults = array(
'numberposts' => -1,
'offset' => 0,
'orderby' => 'menu_order, post_title',
'post_type' => 'our-work',
'depth' => 0,
'show_date' => '',
'date_format' => get_option('date_format'),
'child_of' => 0,
'exclude' => '',
'include' => '',
'title_li' => __(''),
'echo' => 1,
'link_before' => '',
'link_after' => '',
'exclude_tree' => '' );
$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );
$output = '';
$current_page = 0;
// sanitize, mostly to keep spaces out
$r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);
// Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array)
$exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array();
$r['exclude'] = implode( ',', apply_filters('wp_list_post_types_excludes', $exclude_array) );
// Query pages.
$r['hierarchical'] = 0;
$pages = get_posts($r);
if ( !empty($pages) ) {
if ( $r['title_li'] )
$output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
global $wp_query;
if ( ($r['post_type'] == get_query_var('post_type')) || is_attachment() )
$current_page = $wp_query->get_queried_object_id();
$output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
if ( $r['title_li'] )
$output .= '</ul></li>';
}
$output = apply_filters('wp_list_pages', $output, $r);
if ( $r['echo'] )
echo $output;
else
return $output;
}