WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a custom walker and I would like to either get_the_content() (up to the Read More) or get_the_excerpt() to use in this walker, but I can't figure out how to get it to work - it either returns nothing, or if I put an $item->object_id in it (thinking maybe it needed the post/page ID), then it just returns that ID and not the actual post/page text.

I tried googling

Here is my code:

class Salamander_AdventMore_Walker extends Walker_page {
function start_el(&$output, $item, $depth, $args) {
    if ( $depth ) {
        $indent = str_repeat("\t", $depth);
    } else {
        $indent = '';

    $advent_slug = get_post_meta($item->object_id, 'advent-slug', true);
    $advent_small_title = get_post_meta($item->object_id, 'advent-title', true);
    $advent_title = ( !empty($advent_small_title) ? $advent_small_title : $advent_slug);

    $advent_content = apply_filters('the_content', $item->object_id);
    $advent_content = str_replace(']]>', ']]>', $advent_content);

    // this doesn't work
    // $advent_content = get_the_content( $item->object_id, 'Read more ...' ) ;

    $output .= $indent . '
        <h1>' . $advent_title . '</h1>
        <div id="day'. $advent_slug .'" class="daydetail-content">
          <div class="right">
              <h2>' . $advent_title . '</h2>
            '. $advent_content .'
          </div><!-- ends right -->
          <div class="left">
            <!--<a href="#" target="_blank"><img src="http://www.oia.co.za/wp-content/uploads/currency_by_abcdz2000_Flickr-356x703.jpg" width="356" alt=""/></a>-->
          </div><!-- ends left -->
        </div><!-- ends daydatail-content -->
} // ends function
} // ends class
share|improve this question
Alternatively, I'd be happy with how to do a regular query, but with the selection of posts from a particular menu – Amanda Feb 15 '12 at 6:23
up vote 2 down vote accepted

For anyone who might be looking for the same thing, this is what I did in the end:

I abandoned the Custom Walker idea and used wp_get_nav_menu_items to get a list of post IDs from my custom menu, from this tutorial on Digging into WordPress: http://digwp.com/2011/11/html-formatting-custom-menus/

In my functions file, I created this function:

function salamander_fetch_advent_posts() {
 global $post_list;
 $menu_name = 'advent-calendar'; // specify custom menu slug
 if ( ($locations = get_nav_menu_locations() ) && isset( $locations[$menu_name] ) ) {
    $menu = wp_get_nav_menu_object($locations[$menu_name]);
    $menu_items = wp_get_nav_menu_items($menu->term_id);

    $post_list = array();
    foreach ((array) $menu_items as $key => $menu_item) {
        $post_id = $menu_item->object_id;
        $post_list[] = $post_id;
  return $post_list ;

And then in my theme template file, I passed $post_list to a new query, like so:

global $post_list;
if (function_exists( salamander_fetch_advent_posts() )) {

// The Query
$the_query = new WP_Query( array(
    'post__in' => $post_list,
    'post_type' => 'any',
    'posts_per_page' => -1
    ) ) ;

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
    echo '<li>';
    echo '</li>';

// Reset Post Data
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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