WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm sorry if this ambiguous but I'll try my best

I have the following php code from a WordPress Plugin

$url = 'http://mydomain.com/'.$ListingID.'/';

I need to define a value for $ListingID

The value will come from the wordpress database and is found in the table called wp_fsrep_listings

the name of the column in the table is listing_id

and the value is related to a listing page that is similar to a normal wp post page.

Therefore is presume I need to define the "value" in this manner

$ListingID = "value"

How do I define the "value"?

Thank You

share|improve this question
So you have a post ID and you need to get the associated listing ID, but you haven't given us all the needed column names in your table. Can you provide the full schema? – Tom J Nowell May 14 '14 at 22:51

There's a wpdb class in WordPress for you to be able to read/write DB.

To get variable from table, use $wpdb->get_var function. This way:

//set current page ID or define ID in another way - depends on your code
$my_page_id = get_the_ID(); 
global $wpdb;
$ListingID = $wpdb->get_var( "SELECT listing_id FROM ".$wpdb->prefix."fsrep_listings WHERE ID = " . $my_page_id );
echo "<p>Listing id is {$ListingID}</p>";

In the code i presume, that the table has ID column keeping page/post/custom_post_type ID value to match with page/post_custom_post_type.

share|improve this answer
I'm sorry that didn't work. There wasn't an error the URL just displayed as http://mydomain.com// – user24126 Feb 8 '13 at 13:06
This answer assumes a post ID is stored in an ID column, since you never mentioned how the listing ID mapped to the post ID, if any of those assumptions fail then the code will not work as is – Tom J Nowell May 14 '14 at 22:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.