WordPress.org

Ready to get started?Download WordPress

Forums

Pass current author ID into a SQL Query (2 posts)

  1. Nikolas
    Member
    Posted 4 years ago #

    Hello there.
    Is there a way to pass the current author ID, dynamically into a query?
    I will use this to display some fields from MySQL for the current author.

  2. vtxyzzy
    Member
    Posted 4 years ago #

    This is UNTESTED, but should give you a starting point:

    <?php
        // Use this within The Loop
        $author = get_the_author_meta('ID');
        $sql = "SELECT * FROM $wpdb->users WHERE ID = '$author' ";
        $myquery = new WP_Query();
        $results = $myquery->get_results($sql);
    
       // Do stuff with $results
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.