I created multiple PHP pages linked to WordPress's DB, where I created a specific table to get information from a posted form. I want people to login using their WordPress credentials to access the page where I show the content of this table.

I tried this:


//Setup location of WordPress
$absolute_path = $_SERVER['DOCUMENT_ROOT'];
$path_to_file = explode( 'wp-content', $absolute_path );
$path_to_wp = $path_to_file[0];

//Access WordPress
require_once( $path_to_wp.'/wp-load.php' );

But this doesn't work.

  • what do you mean by doesn't work? do you have debugging enabled? do you receive errors? – Milo Jan 5 '15 at 15:51
  • Thanks for your answer! It doesnt work because i use an if to check if an user of wordpress is logged, if it is show me a custom text and if not show me another text. – Daniel Jan 27 '15 at 7:18
  • And if im logged or not it is always false – Daniel Jan 27 '15 at 7:18

Why don't you make it these way:

1) Create Page Template

2) Check if user is logged in

3) if is use $wpdb global var to access database

4) do your stuff with form

it may look like:

 * Template Name: User Form 1
if( ! is_user_logged_in() ){
    wp_redirect( home_url() );


    global $wpdb;
    // http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results
    $forms = $wpdb->get_results( 
        SELECT * 
        FROM my_table_name

    foreach ( $forms as $form ) {
        // do something


or if you want it to be without template structure use it without get_header() or create a header-forms.php and use get_header( 'forms' )

But if you still thinking to do it outside the theme and templates than wait for someoune to answer properly.

| improve this answer | |
  • Thanks for your answer! I dont want to use the page template. I just added a new folder with some php pages with a form(non cms pages) But in place to make a login page to see a list of record of customer that use this form. I want to use the function of wordpress to check if admin of wordpress is logged and if yes he can access this list. i included the header and used the function but it doesnt work :/ – Daniel Jan 27 '15 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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