Support » Plugin: Author Image » Within a custom select query

  • Hello!

    Thanks for this very helpful plugin. I really do appreciate it.

    I have a question about using the_author_image() within a custom select query. In my standard loops I have no problem using this, however within any of my loops that use a custom select query I can’t get the author image to appear.

    My query looks like this:

    SELECT wposts.*
    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    WHERE wposts.ID = wpostmeta.post_id
    AND wpostmeta.meta_key = 'Featured'
    AND wpostmeta.meta_value = 'Blog'
    AND wposts.post_status = 'publish'
    AND wposts.post_type = 'post'
    ORDER BY wposts.post_date DESC
    LIMIT 1

    Thanks again!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Any ideas?

    Moderator Pippin Williamson


    Pippin's Plugins and Plugin Reviewer

    You may need to pass a parameter to the function when inside a custom select query. Check the functions source code in the plugin file. It problably requires a post ID, which may not be getting passed automatically in the custom query.

    Also having this problem using WP_Query where it works fine on single posts but not on archive pages. 🙁

    Try one of these:

    1. call the_post() at the start of your loop.
    2. pass the author_id to the_author_image(). ex: the_author_image( get_user_meta('ID') )

    I’m using this to call multiple categories on my index:

    <?php $recent = new WP_Query(“cat=871,8&showposts=6”); while($recent->have_posts()) : $recent->the_post();?>


    <?php the_author_image(); ?><?php the_author_posts_link() ?>


    <?php the_author_image( get_user_meta(‘ID’) ); ?><?php the_author_posts_link() ?>

    doesn’t seem to fix it. Now sure how to do #1.

    If you are using WP_Query directly, call $query->the_post() to setup the global $post variable (which the_author_image needs to work properly in this case).

    Something like this should work.

    $the_query = new WP_Query( $args );
    while ( $the_query->have_posts() ) : $the_query->the_post();

    Thanks Jeff, but I’m a little confused about how to implement it properly without breaking what I already have. When I add

    <?php $the_query = new WP_Query( $args );
    while ( $the_query->have_posts() ) : $the_query->the_post();


    <?php $recent = new WP_Query("cat=871,8&showposts=6"); while($recent->have_posts()) : $recent->the_post();?>

    it stops the page from grabbing from a specific category and just shows the same post over and over again without the author image displayed.

    [Please post code or markup snippets between backticks or use the code button.]

    The code is not intended to be “cut-n-paste”. You have a proper WP_Query loop already so your problem is somewhere else.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Within a custom select query’ is closed to new replies.