Title: Getting value from MYSQL inside the post loop
Last modified: August 18, 2016

---

# Getting value from MYSQL inside the post loop

 *  [djsap](https://wordpress.org/support/users/djsap/)
 * (@djsap)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/getting-value-from-mysql-inside-the-post-loop/)
 * I’m trying to get a mysql field value inside the post loop, however I can’t figure
   out how to do it as it gives me errors:
 * <?php
    $threadtitle = the_title(); $threadid = $wpdb->get_var(SELECT id wp_forum_threads
   WHERE subject = $threadtitle); echo ‘$threadid’; ?>
 * Basically what I am trying to do is get the ID value from wp_forum_threads where
   subject is equal to the blog entry title. However I can’t figure out why that
   query wouldn’t work.

Viewing 1 replies (of 1 total)

 *  Thread Starter [djsap](https://wordpress.org/support/users/djsap/)
 * (@djsap)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/getting-value-from-mysql-inside-the-post-loop/#post-550022)
 * I seem to have forgotten the FROM in my query, but it still doesn’t work when
   I add it.
 * <?php
    $threadtitle = the_title(); $threadid = $wpdb->get_var(SELECT id FROM 
   wp_forum_threads WHERE subject = $threadtitle); echo ‘$threadid’; ?>

Viewing 1 replies (of 1 total)

The topic ‘Getting value from MYSQL inside the post loop’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [djsap](https://wordpress.org/support/users/djsap/)
 * Last activity: [19 years, 4 months ago](https://wordpress.org/support/topic/getting-value-from-mysql-inside-the-post-loop/#post-550022)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
