Support » Fixing WordPress » Displaying Database Data on a Page based on User

Viewing 2 replies - 1 through 2 (of 2 total)
  • OK, so all I apparently needed was another half a day.

    I used the plugin: Shortcode Exec PHP, then created a shortcode for the below code:

    global $wpdb;
    global $current_user;
    $current_user = wp_get_current_user();
    return $wpdb->get_var(“SELECT field FROM table WHERE field = ‘$current_user->user_login'”);

    … with “output echoed” unticked.

    The shortcode then easily placed in a page.

    I believe I was close on a number of occasions way back, but had the quotes mixed up on the $current_user->user_login variable.

    Glad that’s over. Next challenge now. Hope that might help someone else.

    Sorry, testing code up there ^.

    With SQL injection protection on… last line reads…

    return $wpdb->get_var($wpdb->prepare(“SELECT field FROM table WHERE field = ‘$current_user->user_login'”));

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Displaying Database Data on a Page based on User’ is closed to new replies.