How to register in the Wordpress database from the advanced custom field

0

On my site you can insert new photo albums from the ACF. I created a table in the database that contains the album information, such as name, location, date, and so on. But I have no idea how to enter this album information into the database.

I think the insertion code is like this, but I do not know how to relate it to ACF.

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "bd";


$conn = new mysqli($servername, $username, $password,$dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Conectado!";


$nome_album = $_POST['nome_album']; //Seria o nome que o usuário adiciona no form do ACF
$local_album = $_POST['local_album'];
$data_album = $_POST['data_album'];


$query = "INSERT INTO albums (nome_album, local_album, data_album)
VALUES ('$nome_album', '$local_album', '$data_album')";

if ($conn->query($query) === TRUE) {
    echo "cadastro realizado com sucesso";
} else {
    echo "Error: " . $query . "<br>" . $conn->error;
}

$conn->close();
?>
    
asked by anonymous 07.01.2018 / 15:29

1 answer

0

Look, it is not recommended that you manipulate the Wordpress database in this way, if you are going to use ACF to create fields, it is ideal to do everything for them. Analyzing your scenario I would recommend:

  • Create a Custom Post Type called ALBUNS. You can do it using the Custom Post Type UI plugin - link
  • Here you have two options:

    2.1. Create custom fields using the ACF associated with the created CUSTOM POST TYPE.

    2.2. Create custom taxonomies called LOCAL and DATA (the vantangem here in my opinion is that it is easier to make the WP standard search system see). You can also do it using the Custom Post Type UI plugin - link

    This way you protect your database and use WP's own resources to organize the data you need.

        
    08.01.2018 / 15:11