0

I'm trying to use WP_Query in function.php to display a custom post type on a certain page.

I just can't seem to get it to work, can anyone see issues with my code? nothing is output at all and there are apparently no errors.

/*** add venues to venue page ***/
add_action( 'woo_post_inside_after', 'venue_loop' );

function venue_loop() {
  if ( is_page(123) ) {
    $args = array(
      'post_type' => 'tribe_venue',
      'orderby' => 'title', 
      'order' => 'DESC',
      'posts_per_page' => 10
    );

    $venue_posts = new WP_Query($args);

    if ( $venue_posts->have_posts() ) { 
      while( $venue_posts->have_posts() ) { 
        $venue_posts->the_post();
        $output .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
      }
    }
    return $output;
  }
}
1

Typically, you would be echoing content from an action hook, rather than returning it, and from I can find about this Woo Theme hook that looks to be the case here too.

Try echo $output; instead of return $output;

See:
Clarification on filters and hooks
Difference Between Filter and Action Hooks?

1
  • Excellent, thanks so much, you are correct - just changing that one word makes it work fine :). I will read up on hooks and filters then. Thanks again :) – morktron Nov 4 '13 at 4:41

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.