Support » Plugins » Hacks » get_posts() returns wrong custom post type

  • Resolved fabian.schmid


    So I got a problem here.

    This code is for some kind of an image slider, displaying one post type’s posts at the top of the page. The exact same code works on my development site (same server etc.). I’ve set up a new installation (same version of WP) and created two posts of another (custom) post type first, then a post of the post type, named myposttype here.

    I now get the two posts of the other custom post type displayed in my image slider, instead of the post of post type myposttype.

    <? $myposts = get_posts( array( 'post_type' => 'myposttype' ) );
    		if( $myposts ) : ?>
    		<div class="list_carousel_wrapper">
    			<div class="list_carousel responsive clear">
    				<ul id="slider">
    					<? foreach($myposts as $mypost) : ?>
    						<a href="<?=get_permalink($mypost->ID);?>" title="<?=$mypost->post_title;?>">
    							<div class="imgcontainer"><div class="imgvignette"><img src="<? echo wp_get_attachment_url( get_post_thumbnail_id( (int) $mypost->ID ) ); ?>"></div></div>
    							<div class="vignette"><h4><? echo (empty($mypost->ashortname)) ? $mypost->post_title : $mypost->ashortname; ?></h4><p><? echo $mypost->ateaser; ?></p></div>
    					<? endforeach; ?>
            <? endif; ?>

    Can anyone help me here? Thanks a bunch!

Viewing 1 replies (of 1 total)
  • I was able to solve my problem, though I do not think that I found an answer here. I basically installed WordPress from scratch, uploaded my theme (exactly same code as before), and created two posts of that same post type, which would not show up. I did create these posts before creating any other posts. Last time, I began by adding two posts of another post type (the one that mistakenly showed up later). I don’t know if this was the problem. Anyhow, nothing happened this time, no posts at all showed up.

    Until I changed the setting Front page displays in Settings > Reading to a static page (does not seem to matter what page this is).
    However, I think I had set this very same setting before as well.

    This all might be a bit hard to understand. I won’t bother with it any longer and just be glad it finally works the way I want it to.

Viewing 1 replies (of 1 total)
  • The topic ‘get_posts() returns wrong custom post type’ is closed to new replies.