V
V
VitaliiMayk2018-09-04 03:33:53
WordPress
VitaliiMayk, 2018-09-04 03:33:53

How to display messages from the database on the Contact Form 7 page?

There is a Contact Form 7 form for writing reviews, reviews are stored in the database using the Advanced Contact form 7 DB plugin. How to display reviews in the right place on the page?)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Pupkin, 2018-09-04
@VitaliiMayk

<?php
/*
* Template Name: CF7DB
*/

get_header();

$fid = 2945;  // номер формы
$data = array();
$prev = 0;

// получаем список сохраненных полей
$fields = vsz_cf7_get_db_fields($fid, false);

// получаем все данные сохраненные из формы
// сюда еще фильтр нужно для пагинации или просто ограничения
$query = "SELECT * FROM `".VSZ_CF7_DATA_ENTRY_TABLE_NAME."` WHERE `cf7_id` = ".$fid." ORDER BY `data_id` DESC";
$result = $wpdb->get_results($query);

// формируем массив $data со списком данных, разворачивая из линейного в массив
$one = array();
foreach($result as $row)
{
    if ($prev != 0 && $row->data_id != $prev)
    {
    	$data[] = $one;
    $one = array();
    }
    foreach($fields as $field)
    {
    	if ($row->name == $field)
        	$one[$field] = $row->value;
    }
    $prev = $row->data_id;
}
$data[] = $one;

// если есть какие либо данные выводим в простую таблицу для отображения
if (count($data))
{
  echo '<table>';
  echo "<tr>";
    foreach($fields as $field)
    {
    	echo '<td style="padding:5px">';
        echo "<strong>", $field, "</strong>";
    	echo "</td>";
    }
  echo "</tr>";
    foreach($data as $d)
    {
    echo "<tr>";
        foreach($fields as $field)
        {
        	echo '<td style="padding:5px">';
            echo $d[$field];
        	echo "</td>";
        }
    echo "</tr>";
    }
  echo "</table>";
}

get_footer();

O
Orkhan Hasanli, 2018-09-04
@azerphoenix

Hello!
Create a page template and then use WP_Query if it's a custom post or use wpdb to retrieve the data from the database. Loop through and add data.
And for convenience, in general, I would recommend using:
1) custom post type + custom fields (ACF plugin)
2) And then use WP_Query to display reviews and that's it...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question