WordPress.org

Ready to get started?Download WordPress

Forums

Author Image
Within a custom select query (9 posts)

  1. James Reyes
    Member
    Posted 3 years ago #

    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!

  2. James Reyes
    Member
    Posted 3 years ago #

    Any ideas?

  3. 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.

  4. PGrizz
    Member
    Posted 2 years ago #

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

  5. h0tw1r3
    Member
    Posted 2 years ago #

    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') )
  6. PGrizz
    Member
    Posted 2 years ago #

    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();?>

    Switching

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

    to

    <?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.

  7. h0tw1r3
    Member
    Posted 2 years ago #

    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();
    	the_author_image();
    endwhile;
    wp_reset_postdata();
  8. PGrizz
    Member
    Posted 2 years ago #

    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();
    	the_author_image();
    endwhile;
    wp_reset_postdata();?>

    under

    <?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.]

  9. h0tw1r3
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic