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 learning about shortcodes. My shortcode is working fine. But, I'm not getting the default values for the attributes.

function csf_cap_databaseinfo($atts,$content=null) {
    global $wpdb;

    shortcode_atts( array('title'=>'My Default', 'year'=>'1900'), $atts); 

    $greeting = $wpdb->get_results($wpdb->prepare("SELECT * FROM wp_test;")); 

     $out = '<h3>'.$atts['title'].'</h3> <h3>'.$atts['year'].'</h3><table>
                    <tr>
                        <th style="border:1px solid #e7e7e7; padding:10px; text-align:center">ID</th>
                        <th style="border:1px solid #e7e7e7; padding:10px; text-align:center">Greeting</th>
                    </tr>'; 

    foreach ($greeting as $greet)
        { 
        $out .= '<tr><td style="border:1px solid #e7e7e7; padding:10px; text-align:center">'. $greet->id .'</td>'; 
        $out .= '<td style="border:1px solid #e7e7e7; padding:10px; text-align:center">'. $greet->greeting .'</td></tr>';
        }

      $out .= '</table>'; 



        return $out; 

}

So, if someone types in [db-info] in a post, without any attributes, they aren't getting "My Default" and "1900". If they type in: [db-info title="Hello" year="1973"], it works as expected. What am I doing wrong?

Thanks.

-Laxmidi

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Try:

 $atts = shortcode_atts( array( 'title' => 'My Default', 'year' => '1900' ), $atts ); 
share|improve this answer
    
Hi mfields, Thanks so much for the help. That worked great. –  Laxmidi Aug 30 '11 at 21:22
    
No problem :) Glad I could help. –  mfields Aug 30 '11 at 21:26
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.