Как сделать другой короткий код для всех разных строк из таблицы базы данных в WordPress? - PullRequest
0 голосов
/ 08 марта 2019

Как сделать другой шорткод для всех разных строк из базы данных в WordPress?

шорткод WordPress:

WordPress shortcode
(Щелкните изображения, чтобы увеличить)

База данных:

database

function button_shortcode( $atts, $content = null ) {

    global $wpdb;
    $table_name = $wpdb->prefix.'height8_form';

    $DBP_results = $wpdb->get_results("SELECT * FROM $table_name");

    foreach($DBP_results as $DBP_row) {
        $id = $DBP_row->id;
        $form = $DBP_row->form;
        $label = $DBP_row->label;

        extract( shortcode_atts( array(
            'account' => $id,
            'style' => $label
            ), $atts ) );

    // return '<a href="http://twitter.com/' . esc_attr($account) . '" class="twitter-button ' . esc_attr($style) . '">' . $content . '</a>';
        // return "$id $form" . $content;   
    }   
    return "$id $label $form";
}
add_shortcode('button', 'button_shortcode');

1 Ответ

0 голосов
/ 13 марта 2019

функция button_shortcode ($ atts, $ content = null) {

    global $wpdb;

    $table_name = $wpdb->prefix.'height8_form';

    $atts=shortcode_atts( array(
            'id' => '',
            'bar' => ''
        ), $atts );

    extract($atts);
    $DBP_results = $wpdb->get_results("SELECT * FROM $table_name WHERE id=$id");

    foreach($DBP_results as $DBP_row)
    {
        $id = $DBP_row->id;
        $form = $DBP_row->form;
        $label = $DBP_row->label;

        echo $form;
    }
}
add_shortcode('h8', 'button_shortcode');

короткий код сс

Пример короткого кода страницы

...