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 want to retrieve data from custom table, that I've made inside the wordpress database and display it in a wordpress page , like posts

Thanks in advance

share|improve this question

2 Answers 2

Here is an example code that will get the data and then display it:

global $wpdb;
// this adds the prefix which is set by the user upon instillation of wordpress
$table_name = $wpdb->prefix . "your_table_name";
// this will get the data from your table
$retrieve_data = $wpdb->get_results( "SELECT * FROM $table_name" );
<ul>
foreach ($retrieve_data as $retrieved_data){ ?>
<li><?php echo $retrieved_data->column_name;?></li>
<li><?php echo $retrieved_data->another_column_name;?></li>
<li><?php echo $retrieved_data->as_many_columns_as_you_have;?></li>
<?php 
}
?>
</ul>
<?php

Its good practice to use unique names for variables and functions, so you may want to add a unique prefix to all your variables or functions IE: ( $prefix_table_name where "prefix" would be something unique such as the abbreviation of your theme or plugin. )

Reference - wpdb - codex

share|improve this answer

Sounds like you're looking for $wpdb. You'll need to write all your own functions and such. I strongly recommend sticking to the established naming conventions (stuff like the_blah and get_blah, maybe with a prefix) for ease of readability and for consistency.

share|improve this answer

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.