Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have 6 authors in my blog page. I have profile for each of the authors. I want to show the posts of the authors dynamically under their own profile. I tried the following but it showed all posts. with this code it is showing the posts in all profiles not specific profiles. What changes should i make?

$current_author = get_query_var('author');
$author_posts=  get_posts( 'author='.$current_author->id.'&posts_per_page=1&order=DESC&orderby=post_date' );
if($author_posts){
  echo '<ul>';
  foreach ($author_posts as $author_post)  {
    echo '<li><a href="'.get_permalink($author_post->ID).'">'.$author_post- >post_title.'</a>   </li>';
  }
  echo '</ul>';
}

I use the following function to show the Image and description about the author

function ajaxified_function() 
{ 
$post = get_post($_POST['post_id']);
$feat_image = get_the_post_thumbnail($post->ID);
$desc_values = get_post_custom_values("description",$post->ID);
    if( is_array( $desc_values ) )
    {
        foreach($desc_values as $key => $value );
    }
echo '<div id="bloggers_feat_img">'.$feat_image.'</div>'.$post->post_.'<div class="bloggers_title">'.$post->post_title.'</div><div id="bloggers_desc">'.$value.'</div><br/><div id="bloggers_postContent">'.$post->post_content.'</div><div>'.$author.'</div>';
die();
}

Following js is which I use to show the above in a lightbox when clicking on a link

 jQuery(document).ready(function (){
 jQuery('#options_to_connect a').on('click',function(event){         
event.preventDefault();
var post_id = jQuery(this).parent().attr('class'); 
jQuery.ajax({  
type: "POST",                  
url:  'http:www.myblog.com/wp-admin/admin-ajax.php',  
   data: 'action=ajaxified_function&post_id='+post_id,    
   success: function (msg) {                                        
       jQuery('#cboxLoadedContent').html(msg);
   },
   error: function () {                  
  alert('Error');               
   }  
  });           
  });       
});      
share|improve this question
2  
Stop deleting your questions. Improve them instead! –  toscho Apr 3 '13 at 11:42
    
Sorry about that.. I am not getting any response.. Thats y –  MidhuN Apr 3 '13 at 11:43
2  
The correct reaction to a lack of responses is improvement, not deletion. –  toscho Apr 3 '13 at 11:44
    
I dont knw how more to improve...This is what I have and I think I am clear about my question –  MidhuN Apr 3 '13 at 11:45
1  
Read 1, 2, 3 and 4. –  toscho Apr 3 '13 at 11:48

1 Answer 1

Basic debugging...

$current_author = get_query_var('author');
var_dump($current_author);

... would reveal that $current_author is a string, not an object. The problem is that you are trying to use the string as an object in the query.

get_posts( 'author='.$current_author->id.'&posts_per_page=1&order=DESC&orderby=post_date' );

Change $current_author->id to $current_author and the query works.

$author_posts =  get_posts( 'author='.$current_author.'&posts_per_page=1&order=DESC&orderby=post_date' );
share|improve this answer
    
It didnt work.Still It is the same. Posts are showing for all profiles –  MidhuN Apr 3 '13 at 13:19
    
I have edited my question –  MidhuN Apr 3 '13 at 13:28
    
I ran the code I posted, and it works, assuming the get_query_var('author') value is set correctly. Are you sure that value is set and is correct? –  s_ha_dum Apr 3 '13 at 13:49
    
I think that's where my problem is .please tell me How to set that value? –  MidhuN Apr 3 '13 at 14:00
    
Is this the normal "author" page or something you've created? –  s_ha_dum Apr 3 '13 at 14:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.