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.
function themeperauthor_need_switch() {
    global $post;
  if ( $get_post_type == 'weblogs' )  {
    return get_the_author_meta('themeperauthor', $user->ID);
  }
  return "";
}

It doesn't return anything

share|improve this question
add comment

3 Answers

You are using get_post_type as variable instead of a function try:

function themeperauthor_need_switch() {
    global $post;
  if ( get_post_type($post) == 'weblogs' )  {
    return get_the_author_meta('themeperauthor', $user->ID);
  }
  return "";
}
share|improve this answer
    
Actually I am trying to switch theme per author based on the given profile field by each author. So I need to get the author profile data get_the_author_meta('themeperauthor', $user->ID); –  puanthanh Mar 2 '11 at 11:41
    
Suppose if I give- return "twentyten"; than theme get switched but this code return get_the_author_meta('themeperauthor', $user->ID); doesn't show pull in any data. –  puanthanh Mar 2 '11 at 11:42
add comment

Hi @puanthanh:

Well to start $user is not in scope. But since you've given very few details I'm not sure how to suggest you assign a value. Maybe update your question with more details?

share|improve this answer
    
I want to fetch the author data profile field name 'themeperauthor' Do I need to put this on the top <?php $curauth = (get_query_var('author_name')) ? get_user_by('slug', get_query_var('author_name')) : get_userdata(get_query_var('author')); ?> Will it fetch the author profile field data? –  puanthanh Mar 2 '11 at 11:51
    
Thanks MikeSchinkel for pointing it out. my correct code now is function themeperauthor_need_switch() { global $post; global $user_id; $author_id=$post->post_author; if ( get_post_type($post) == 'weblogs' ) { return get_the_author_meta('themeperauthor', $author_id); } return ""; } Thanks all. I am new here and I already like this site. English is my second lang. sorry about it –  puanthanh Mar 2 '11 at 12:06
    
@puanthanh - To add code you should update your question or post your own answer. Code posting in comments is unreadable. –  MikeSchinkel Mar 2 '11 at 20:43
add comment

Not really sure what you're aiming to do, but maybe..

function themeperauthor_need_switch() {
    global $post
    //, $current_user;
    if( !isset( $post->post_type ) )
        return '';
    if ( $post->post_type == 'weblogs' )
        return get_the_author_meta( 'themeperauthor', 
            $post->post_author
            //$current_user->ID
        );
    return '';
}

Assumed you want to get meta based on post author, but can be switched for the current user if that's actually what you want(left alternate lines in the code, but commented out).

NOTE: If using $current_user, you should check there's a user logged in first.. if( is_user_logged_in() ) or similar..

share|improve this answer
add comment

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.