Excerpt not pulling correct content. (4 posts)

  1. J
    Posted 3 years ago #

    Hi guys quick query,

    I am building a site for a travel company. I have made parent categories for the Main countries then each parent category has a child category for individual trips.

    My plan was to have the post in the parent cat to outline the country etc then at the bottom pull in excerpts of 5 posts in its child cat.

    Anyway iit does this fine pulls in the child Image and Title perfect. However the excerpts for each child post is the content from the parent post so Im a little baffled if you like. Heres a page so you can see what I mean -


    Scroll down to the some suggested itineries and you will see what I mean.

    Heres the code Im using to pull in the child cat content into the parent cats post :-

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum's parser. ]

    					global $post;
    					$categories = get_the_category();
    					$category = $categories[0];
    					$cat_ID = $category->cat_ID;
    					$myposts = get_posts("numberposts=5&category=$cat_ID&exclude=107,78,64,203,206,208,210,213,215,217,219,221,223");
    					<?php foreach($myposts as $post) :?>
    				<div class="image-tab-post">		<?php the_post_thumbnail('width:170px'  ); ?></div>
    					<div class="content-tab-post">	<strong class="title"><a>"><?php the_title(); ?></a>	<?php the_excerpt(); ?>
    					<div class="clear"></div>
    					<?php endforeach; ?>

    Now I may have done a backwards way, Im not godlike in wordpress but hope to be one day so any constructive criticism into how Ive done it is also welcome.

    Any help would be awesome,


  2. J
    Posted 3 years ago #

    Any ideas dudes? Im baffled by it

  3. Michael
    Forum Moderator
    Posted 3 years ago #

    read the Codex:

    your code is missing setup_postdata() -

    foreach( $myposts as $post ) :	setup_postdata($post); ?>
  4. J
    Posted 3 years ago #

    You sir are a legend, such an easy thing knew it was something silly. Thankyou for your advice greatly appreciated!

Topic Closed

This topic has been closed to new replies.

About this Topic