0

I'm trying to output a custom post type but nothing shows up. The code is very simple - what could I be missing?

<?php
$favorites = new WP_Query(array('post_type' => 'favorites', 'posts_per_page' => 10));

while ($favorites->have_posts()) : $favorites->the_post();

echo '<li><a href="' . bloginfo('template_directory') . the_post_thumbnail('large') . '" rel="thumbnail" title="&lt;a href=\'' .   simple_fields_get_post_value(get_the_id(), array(8, 3), true) . '\'&gt;' . the_title() . '&lt;/a&gt;"><img class="rounded" src="' . bloginfo('template_directory') .     the_post_thumbnail(array(101,99)) . '" alt="' . the_title() . '" /></a></li>';

endwhile;
?>

1 Answer 1

2

Have you checked that;

  • You have definitely registered a post type called favorites (note plural)
  • The browser is not choking on your markup (your HTML is invalid - for starters, you should wrap list items in a <ul>
  • The function simple_fields_get_post_value() exists and is working correctly
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reply, yes I've checked all three of them. Got it to work just a couple of minutes ago - apparently I can't have this code running in the footer include. It will only print out the posts if I use it in a template file (perhaps also elsewhere). Is there any way I can run a query in the footer? Otherwise I'd have to change a lot of the layout.
That's crazy - if your code works in index.php or wherever, then it should work in your footer. Have you checked that CSS is not hiding it? Run the page then view source in your browser to see if it's actually there.
See below. Do you think these two changes were the reason? I'm not sure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.