Just Start Typing Text and Press Enter

alt text
PANKAJ SINGH
Web Designer & Developer

DRINK A COFFEE WITH ME TODAY

Loading...
Message Snet
Error!

Blog posts

Menu
Close
Apr 16, 2016

How to fetch data from custom table or any table in wordpress

1 comment | By
How to fetch data from custom table or any table in wordpress

 

<?php

/*

Template Name: customtemplate

* @pankaj singh

*/

get_header(); ?>

            <div class=”row-fluid”>                      

                                    <div class=”content-area”>

                                                <main id=”main” class=”site-main” role=”main”>

                                               

                                                <?php

                                                global $wpdb;

// this adds the prefix which is set by the user upon instillation of wordpress

$table_name = $wpdb->prefix . “users”;

// this will get the data from your table

$retrieve_data = $wpdb->get_results( “SELECT * FROM $table_name” );

?>

<ul>

<?php

foreach ($retrieve_data as $retrieved_data){ ?>

<li><?php echo $retrieved_data->user_login;?></li>

<li><?php echo $retrieved_data->user_pass;?></li>

<li><?php echo $retrieved_data->user_email;?></li>

<?php

}

?>

</ul>

            </main><!– #main –>                                               

                                    </div><!– #primary –>                      

            </div><!– .row-fluid –>

<?php get_footer(); ?>

 

 

1 Comment

  • admin
    April 27, 2015 - 10:30 am Reply

Leave A Comment

Author Details

My name is Pankaj Singh and I am a web designer and developer with over 3+ years of professional experience in the design industry, currently living in New Delhi, India. I have a Master of Computer Application from GGSIPU University, and my primary focus and inspiration for studies is Web Development.

Share Post