Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.