0

i have a wp db. and i added a table "wp_mapmus"

now i want to show these datas on post page with shortcode. But there is an error. and i dont know php very well. i only use same plugins. what is the correct code ?

my code:

function veri_cek($atts, $content = null) { extract( shortcode_atts( array( 'id' => '0', ), $atts ) );

    global $wpdb;
    $table = $wpdb->prefix . 'mapmus';
    $sql = 'SELECT point FROM '.$table.' WHERE id = '.$id.'';
    $results = $wpdb->get_results($sql);
    foreach ( $results as $result )
{
    return ' Point: '.$result.' ';
}
}
add_shortcode( 'veri', 'veri_cek' );
2
  • 2
    What is the error?
    – s_ha_dum
    Oct 18, 2013 at 14:58
  • it doesnt show anythng. Oct 18, 2013 at 20:09

1 Answer 1

1

I am not sure about your error as well, but one thing you are doing wrong. Returning data.

You should be 'collecting' them and then returning.

$data = '';
foreach ( $results as $result )
{
    $data .= ' Point: '.$result.' ';
}

return $data;

Try this loop.

2
  • thanks but it break the page. Oct 18, 2013 at 20:18
  • Then give all your code, or a screen how it breaks page. Since in the loop is nothing, that would cause a breaking of the code. This depends on a lot of factors, maybe a variable $result is an array, and we are echoing it. I just worked with your code, which you provided. Oct 19, 2013 at 9:10

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.