I am creating a plug-in for WordPress. With this plug-in, the admin can insert from the backend a project. These projects always get a value of "0" in the database.
From the ui everybody can insert a project to, but these projects get a value of "1" in the database.
I only want to display the projects with the value of "0" on a page in the GUI.
with this code, I get the database items in my class.
public function getProjectenList() {
global $wpdb;
$return_array = array();
$result_array = $wpdb->get_results("SELECT * FROM `" . $wpdb->prefix .
"ivs_canvas_tabel` ORDER BY `id`", ARRAY_A);
This is the code in the view:
<?php
if ($projecten->getNrOfProjecten() < 1) {
?>
<tr><td colspan="4">Voeg een project of media-uiting toe</tr>
<?php
} else {
$cat_list = $projecten->getProjectenList();
//** Show all projects in the tabel
foreach ($cat_list as $project_obj) {
// Create update link
$params = array('action' => 'update', 'id' => $project_obj->getId());
// Add params to base url update link
$upd_link = add_query_arg($params, $base_url);
// Create delete link
$params = array('action' => 'delete', 'id' => $project_obj->getId());
// Add params to base url delete link
$del_link = add_query_arg($params, $base_url);
?>
<tr><td width="10" style="vertical-align: top;"><?php echo $project_obj->getId(); ?>
</td>
<?php
// If update and id match show update form
// Add hidden field id for id transfer
if (($action == 'update') &&
($project_obj->getId() == $get_array['id'])) {
?>
<td width="150" style="vertical-align: top;"><input type="hidden" name="id" value="<?php echo $project_obj->getId(); ?>">
<input type="text" name="naam" value="<?php echo $project_obj->getNaam(); ?>"></td>
<td width="10" style="vertical-align: top;"><input type="text" name="level" value ="<?php echo $project_obj->getLevel(); ?>"></td>
<td width="300" style="vertical-align: top;"><textarea name="beschrijving" maxlength="200"> <?php echo $project_obj->getBeschrijving(); ?></textarea></td>
<td><input type='file' name='afbeelding' value="<?= IVS_CANVAS_PLUGIN_INCLUDES_UPLOAD_IMGS_DIR_URL . $project_obj->getAfbeelding() ?>"></td>
<td colspan="2"><input type="submit" name="update"
value="Updaten"/></td>
<?php } else { ?>
<td width="150" style="vertical-align: top;"><?php echo
$project_obj->getNaam(); ?></td>
<td width="10" style="vertical-align: top;"><?php echo
$project_obj->getLevel(); ?></td>
<td width="300" style="vertical-align: top;"><?php echo $project_obj->getBeschrijving(); ?></td>
<td width="100"><img src="<?= IVS_CANVAS_PLUGIN_INCLUDES_UPLOAD_IMGS_DIR_URL . $project_obj->getAfbeelding() ?>" width="100px" height="100px"/></td></td>
<?php
if ($action !== 'update') {
// If action is update don’t show the action button
?>
<td><button><a href="<?php echo $upd_link; ?
>">Wijzigen</a></button></td>
<td><button><a href="<?php echo $del_link; ?
>">Verwijderen</a></button></td>
<?php
} // if action !== update
?>
<?php } // if acton !== update ?>
</tr>
<?php
}
}
?>
The table structure
$sql = "CREATE TABLE $table_name (
id int (100) NOT NULL AUTO_INCREMENT,
naam varchar (255) NOT NULL,
level int (10) NOT NULL,
beschrijving varchar (1024) NOT NULL,
afbeelding varchar(1024) NOT NULL,
status int (1) NOT NULL,
PRIMARY KEY (id)
)
I hope someone can help me out!