Ready to get started?Download WordPress


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

  1. Nikolas
    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
    Posted 4 years ago #

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

        // 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


No tags yet.