tags:

views:

27

answers:

2

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  A: 

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
TheDeadMedic
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.
Staffan Estberg
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.
TheDeadMedic
See below. Do you think these two changes were the reason? I'm not sure.
Staffan Estberg
A: 

Got the query working in footer now. Weird, I've tried dozens of approaches and now suddenly it just works. I guess one thing is not escaping php and using global $var, like so -

<?php
global $loop;
$loop = new WP_Query("post_type=favorites");
?>
<?php while (have_posts()) : the_post(); ?>
<?php
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>'; ?>
<?php endwhile;?>
Staffan Estberg