0

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

1 Answer 1

3

Try:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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