[wp-testers] possible bug in get_posts

michael at mfields.org michael at mfields.org
Mon Jan 31 00:04:38 UTC 2011


I don't think that there is a bug in core. Your code looks a bit off to me
though. Please try the following:

$movies = get_posts( array(
	'numberposts' => '-1',
	'post_type'   => 'movies',
	) );

/* Backup global $post object !IMPORTANT! */
$_post_backup = $post;

foreach( (array) $movies as $post ) {
	setup_postdata( $post );
	print '<li><a href=' . get_permalink() . ' title="' .
sprintf(esc_attr__('Permalink to %s'), the_title_attribute('echo=0')) .
'" rel="bookmark">' . get_the_title() . '</a></li>';
}

/* Restore global $post object !IMPORTANT! */
$post = $_post_backup;

Best wishes,
-Mike

> I believe that I may have accidently stumbled upon a bug in the
> get_posts function.  It can be replicated with the code below, the bug I
> feel is as follows when the below code is used for posts and pages it
> works fine, however when used for custom post types, it seems to be
> ignoring the custom post type and outputting the list of posts as per
> the default.  I have tried and tried to login on the trac, but my
> wordpress.org username and password doesn't seem to work on it.  If
> people here feel that it is in fact a bug please could someone file it
> for me, or if not could someone tell me what it is I have done wrong ?
>
> $post_types = get_post_types(array('public' => true, '_builtin' =>
> false), 'objects');
>
> foreach ($post_types as $post_type) {
>    // Set options for query
>    $post_args = array(
>     'numberposts' => '-1',
>      'post_type' => 'movies',
> );
>
> $theposts = get_posts($post_args);
>
> foreach($theposts as $thepost) {
>    $custom_post_types .= '<li><a href=' . get_permalink() . ' title="' .
> sprintf(esc_attr__('Permalink to %s'), the_title_attribute('echo=0')) .
> '" rel="bookmark">' . get_the_title() . '</a></li>';
> }
>
>
> _______________________________________________
> wp-testers mailing list
> wp-testers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-testers
>




More information about the wp-testers mailing list