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 will begin by saying this is unfinished, and I am new to web programming. That being said, I am trying to create a javascript slide show that remembers the last slide a Wordpress (loggedin user) was viewing.

I have hand entered one record into a new Wordpress table called wp_slideshow. The columns in that table are user and last_slide. The current data is one record, user = admin, last_slide = 3.

I just want to get the current userid that is logged in from wordpress and then get the last_slide number. Once I get it I need to integrate the last slide into my javascript code and begin displaying the last slide. Any suggestions on why my current code (just for getting one record from my wp_slideshow table does not work?

Here is my code:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post">

        <div class="entry">

            <?php the_content(); ?>
            <?php edit_post_link('Edit.', '<p>', '</p>');?>

            <?php global $current_user;?>
            <?php get_currentuserinfo();?>
            <?php $user_id = $current_user->ID;?>

            <?php global $wpdb;?>
            $thenbr = $wpdb->get_row( $wpdb->slideshow( "SELECT * FROM $wpdb->slideshow WHERE user = "admin"" ) );
            echo $thenbr->last_slide; 


        <SCRIPT LANGUAGE="JavaScript">      
        var num=1
        img1 = new Image ()
        img1.src = "http://localhost/wp-content/uploads/2011/11/nervous.gif"
        img2 = new Image ()
        img2.src = "interference.gif"
        img3 = new Image ()
        img3.src = "message.gif"
        img4 = new Image ()
        img4.src = "nervous.gif" 

        text1 = "Text for Picture One"
        text2 = "Text for Picture Two"
        text3 = "Text for Picture Three"
        text4 = "Text for Picture Four"

        function slideshowUp()
        if (num==5)

        function slideshowBack()
        if (num==0)


        <!-- The Image and Form Codes are Below --> 

        <IMG SRC="information.gif" NAME="mypic" BORDER=0 HEIGHT="300" WIDTH="300">

        <FORM NAME="joe">
        <INPUT TYPE="text" WIDTH="300" NAME="burns" VALUE="Text For Picture One">

        <A HREF="JavaScript:slideshowBack()"> Back</A>

        <A HREF="JavaScript:slideshowUp()"> Next</A> 

    <?php endwhile; endif; ?>
share|improve this question

You're doing it wrong ...

Don't use a custom table for this!

What you can do instead is store this information in user meta (in the wp_usermeta table).

Let's say you want to store last_slide=3 in the user meta table. You'd use the following:

update_user_meta( $user_id, 'last_slide', 3 );

To get this back, you'd call:

get_user_meta( $user_id, 'last_slide', true );

I recommend doing it this way so you don't try to reinvent the wheel with a custom table and custom queries.

Now to answer the actual question ...

In your code, you try to get the value back out of your custom table with this call:

$thenbr = $wpdb->get_row( $wpdb->slideshow( "SELECT * FROM $wpdb->slideshow WHERE user = "admin"" ) );

That basically won't work. The $wpdb object has no method called slideshow(), so calling $wpdb->slideshow() will throw an error, not return any data. Re-read the Codex article on using this object to select a row.

What you want instead would be along the lines of:

$thenbr = $wpdb->get_row( "SELECT * FROM $wpdb->slideshow WHERE user = 'admin'" );

But again, I highly advise against using custom queries and custom tables!

share|improve this answer
Thank you very much. I will try that. – Alan Nov 4 '11 at 13:51

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.