• i want to make an if then statement of

    if author has posts

    or posts>0

    im not quite sure where to start

Viewing 6 replies - 1 through 6 (of 6 total)
  • get_posts accepts the same parameters as WP_Query, so you can always check the parameter documentation for that if you need help getting started. Here’s the documentation using author as a parameter for WP_Query: https://codex.www.ads-software.com/Class_Reference/WP_Query#Author_Parameters

    Example (where 63 is the author’s user id)

    $array = get_posts('author=63');
    if(!empty($array)) {
    // do stuff if they have posts
    } else {
    // do stuff if they don't have posts
    }

    Thread Starter posthawk

    (@posthawk)

    is there any way this could be applied to all authors?

    Ok, what exactly are you trying to do?

    Thread Starter posthawk

    (@posthawk)

    this code displays author avatar on pages that they post with links to their website. however it is showing a random avatar on profiles that havent posted anything yet.

    so i wanted an if (author has posted) then display this code. else dont display this code

    <a style="margin: 0px 25px" title="<?php the_author_meta( 'display_name' ); ?>’s Website" alt="Author Webite Link"<a href="<?php the_author_meta( 'user_url' ); ?>"><?php echo get_avatar( get_the_author_meta('ID'), 150); ?></a></a>

    Sure, just put your code where it says do stuff if they have posts.

    $id = get_the_author_meta('ID');
    $array = get_posts('author='.$id);
    if(!empty($array)) {
    // do stuff if they have posts
    } else {
    // do stuff if they don't have posts
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Php help’ is closed to new replies.