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() ) { 
        $output .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
    return $output;

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;

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

  • 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.