I was wondering to know if it's possible to use global posts with custom_types. I was working with this function:

global $post; 
$myposts = get_posts('numberposts=4&offset=1& category=3,4'); 
foreach($myposts as $post) : 
    setup_postdata($post); ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Visualizza <?php the_title(); ?>"><img src="<?php echo get_option('home'); ?>/wp-content/uploads/posthumb/<?php $values = get_post_custom_values("Image"); echo $values[0]; ?>" alt="<?php the_title(); ?>" /></a>
<?php endforeach;

As soon as I've moved the post from the standard articles type to a new custom post type, this stopped working. The category is still the same. Can I get it work again in any kind of way?

Thank you very much for your reply.


By default get_posts() uses a default post type of post.

If you want to select from a CPT then you need this:

$myposts = get_posts('numberposts=4&offset=1&category=3,4&post_type=YOUr_CPT_HERE');
  • Thanks Brady! I was going crazy trying to find that option!!! Thank you so much!!! – FrA Sep 11 '12 at 13:01

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.