With get_posts you have to use “category”. Can you show us the whole foreach you are using to display the posts.
<? $latestPost=get_posts('numberposts=2&category=3');
foreach($latestPost as $pst){?>
<? $contentAge=$pst->post_content; $contentAg=substr($contentAge,0,57); ?>
<? $custom_fields = get_post_custom($pst->ID); $post_category = get_the_category($pst->ID); ?>
<li><a href="<?php bloginfo('url'); ?>/<?=$post_category[0]->category_nicename;?>/<?=$pst->post_name;?>/"><?=$pst->post_title?></a><br /><?=$contentAg?>...<br /><div class="more"><a href="<?php bloginfo('url'); ?>/<?=$post_category[0]->category_nicename;?>/<?=$pst->post_name;?>/">More...</a></div></li>
<? } ?>
As per my initial post I have tried using category but there were still problems with it
Have you tried with setup_postdata. Like so:
<? $latestPost=get_posts('numberposts=2&category=3');
foreach($latestPost as $pst){
setup_postdata($pst);
?>
<? $contentAge=$pst->post_content; $contentAg=substr($contentAge,0,57); ?>
<? $custom_fields = get_post_custom($pst->ID); $post_category = get_the_category($pst->ID); ?>
<li><a href="<?php bloginfo('url'); ?>/<?=$post_category[0]->category_nicename;?>/<?=$pst->post_name;?>/"><?=$pst->post_title?></a><br /><?=$contentAg?>...<br /><div class="more"><a href="<?php bloginfo('url'); ?>/<?=$post_category[0]->category_nicename;?>/<?=$pst->post_name;?>/">More...</a></div></li>
<? } ?>
ok my code is now shown below and it shows no posts but its not relatest the setup_postdata($pst); line as it was like that before i just put that in:
<? $latestPost=get_posts('numberposts=3&category=-3');
foreach($latestPost as $pst){
setup_postdata($pst);?>
<? $custom_fields = get_post_custom($pst->ID); /*print_r($custom_fields);*/ $post_category = get_the_category($pst->ID); ?>
<li><a href="<?php bloginfo('url'); ?>/<?=$post_category[0]->category_nicename;?>/<?=$pst->post_name;?>/"><span><?=$pst->post_title?></span><br /><?php echo $custom_fields['Location'][0]; ?><? if($custom_fields['Salary'][0]!=''){?><br /><span><? echo $custom_fields['Salary'][0]; ?></span><? } ?></a></li>
<? } ?>