Image name is not saved in database codeigniter 3 - database

here I am adding attach file input in the add_incident form, but after submitting form the file name is not saved in the database and also the file is not saved in upload folder.the uploads folder path is correct. running
echo "<pre>";
print_r($_FILES);
die;
Output is:
Array
(
[filename] => Array
(
[name] => mot-testing-station 2.eps
[type] => application/postscript
[tmp_name] => /opt/lampp/temp/phpMSzQT6
[error] => 0
[size] => 405159
)
)
but it doesn't give any output and it just continue to submit the form and create new incident.
can anyone please help me what am I missing ?
view.php
<h2 class="heading">Add Incidents</h2>
<?php echo form_open_multipart('incidents_add'); ?>
<div class="row">
<div class="form-group col-md-4">
<label for="email">Incidents ID</label>
<input type="text" class="form-control" id="T_id" placeholder="Name" name="T_id"value="<?php echo $T_id;?>" readonly >
</div>
<div >
<input id = "choose_image" type="file" name="filename" size="20" />
</div>
<div class="col-md-12">
<div class="btn-section float-right">
<button class="btn btn-outline-primary" value="Create"><i class="fa fa-plus-circle" aria-hidden="true"></i> Create</button>
</div>
</div>
</div>
</form>
controller.php
function add()
{
$existing_count = $this->incidents_model->get_task_count();
$data['T_id'] = 'T'.sprintf("%'.03d\n",$existing_count+1);
$this->form_validation->set_rules('Status', 'Status ', 'required');
$this->form_validation->set_rules('Priority', 'Priority' , 'required');
$this->form_validation->set_rules('Description', 'Description' , 'required');
$data['incidents'] = $this->incidents_model->getIncidentsDetails();
$data['T_id'] = $this->incidents_model->get_task_count();
$data['company_name'] = $this->incidents_model->getAllCompanyName();
if (isset($_FILES['filename'])){
// print_r($_FILES);
// die;
$file_name = time().'_'.$_FILES['filename']['name'];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|dox|pdf';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$config['file_name'] = $file_name;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('filename'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/incidents/add', $error);
}
else
{
$data = array('file' =>$this->upload->data());
$this->load->view('admin/incidents/add', $data);
}
}
if ($this->form_validation->run() ==true)
{
$this->incidents_model->add();
$this->session->set_flashdata ('success','Incidents Added Sucessfully');
redirect('admin/incidents/index' ,$data);
}
else{
$this->load->view('admin/incidents/add', $data);
}
}

So here is how I solved the issue, I have added
$data['file'] = $this->incidents_model->add($image_name);
and that solved my issue.
controller:
function add()
{
$existing_count = $this->incidents_model->get_task_count();
$data['T_id'] = 'T'.sprintf("%'.03d\n",$existing_count+1);
$this->form_validation->set_rules('T_id', 'Tasks Id', 'required');
$this->form_validation->set_rules('Tname', 'Tasks Name' , 'required');
$this->form_validation->set_rules('Cname', 'Company Name ', 'required');
$this->form_validation->set_rules('Pname', 'Project Name' , 'required');
$this->form_validation->set_rules('Pversion', 'Project Version', 'required');
$this->form_validation->set_rules('Rform', 'Report Form ', 'required');
$this->form_validation->set_rules('Internal', 'Internal ', 'required');
$this->form_validation->set_rules('Assignto', 'Assign To' , 'required');
$this->form_validation->set_rules('Sdate', 'Start Date', 'required');
$this->form_validation->set_rules('Edate', 'End Date' , 'required');
$this->form_validation->set_rules('Status', 'Status ', 'required');
$this->form_validation->set_rules('Priority', 'Priority' , 'required');
$this->form_validation->set_rules('Description', 'Description' , 'required');
$data['incidents'] = $this->incidents_model->getIncidentsDetails();
$data['T_id'] = $this->incidents_model->get_task_count();
$data['company_name'] = $this->incidents_model->getAllCompanyName();
if ($this->form_validation->run() ==true)
{
if (isset($_FILES['filename']))
{
// echo "<pre>";
// print_r($_FILES);
// die;
$file_name = time().'_'.$_FILES['filename']['name'];
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|dox|pdf';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$config['overwrite'] = TRUE;
$config['file_name'] = $file_name;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('filename'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/incidents/add', $error);
}
else
{
$image_data = $this->upload->data();
$image_name = $image_data['file_name'];
$data =array(
'file' => $image_data['file_name']
);
$data['file'] = $this->incidents_model->add($image_name);
}
}
$this->session->set_flashdata ('success','Incidents Added Sucessfully');
redirect('admin/incidents/index' ,$data);
}
else{
$this->load->view('admin/incidents/add', $data);
}
}
and modified my add function in model as below:
function add()
{
$arr['incidents_id'] = $this->input->post('T_id');
$arr['incident_name'] = $this->input->post('Tname');
$arr['company_name'] = $this->input->post('Cname');
$arr['project_name'] = $this->input->post('Pname');
$arr['project_version'] = $this->input->post('Pversion');
$arr['report_form'] = $this->input->post('Rform');
$arr['internal'] = $this->input->post('Internal');
$arr['assign_to'] = $this->input->post('Assignto');
$arr['start_date'] = $this->input->post('Sdate');
$arr['end_date'] = $this->input->post('Edate');
$arr['status'] = $this->input->post('Status');
$arr['priority'] = $this->input->post('Priority');
$arr['description'] = $this->input->post('Description');
$arr['initial_status'] = 0 ;
$arr['flag'] = 1;
$arr['file'] = time().'_'.$_FILES['filename']['name'];
$this->db->insert('incidents',$arr);
$insert_id = $this->db->insert_id();
$arr1['incident_id'] = $insert_id;
$arr1['incident_status'] = $this->input->post('Status');
$arr1['incident_description'] = $this->input->post('Description');
$this->db->insert('incident_status',$arr1);
}

Related

Can't display file validation error message in codeigniter

I have set form validation in my project. My all form validation is working but I can not display file input validation error message. The file is upload properly, it doesn't show any error when I upload an invalid file. I try a lot of ways but anythings are not working.
I give here only file uploading related code.
My controller
$config = [
'upload_path'=>'./uploads/image/',
'allowed_types'=>'jpg|png',
'max_size' => '400',
'overwrite' => FALSE
];
$this->load->library('upload', $config);
if(!($this->form_validation->run() && $this->upload->do_upload()))
{
$view = array('error' => $this->upload->display_errors());
$view['admin_view'] = "admin/add_books";
$this->load->view('layouts/admin_layout', $view);
}
MY model
public function add_books()
{
$data = $this->upload->data();
$image_path = base_url("uploads/image/".$data['raw_name'].$data['file_ext']);
$data = array(
'book_name' => $this->input->post('book_name'),
'description' => $this->input->post('description'),
'author' => $this->input->post('author'),
'publisher' => $this->input->post('publisher'),
'price' => $this->input->post('price'),
'quantity' => $this->input->post('quantity'),
'categoryId' => $this->input->post('categoryId'),
'book_image' => $image_path,
'userId' => $this->session->userdata('id'),
'status' => $this->input->post('status')
);
$insert_book = $this->db->insert('books', $data);
return $insert_book;
}
My view
<div class="form-group row">
<label for="book_image" class="col-sm-2 col-form-label">Book image</label>
<div class="col-sm-6">
<?= form_upload(['name'=>'userfile', 'class'=>'form-control'])?>
<div class="text-secondary">* Upload PNG, JPG format. Image should not be more than 400KB</div>
</div>
<div class="col-sm-4">
<div class="text-danger form-error"><?= form_error('userfile')?></div>
</div>
</div>
How it can be fixed?
I think you should separate $this->form_validation->run() and $this->upload->do_upload()
$view = array();
if($this->form_validation->run() == true){
if(!$this->upload->do_upload('userfile')){
$view['error'] = $this->upload->display_errors();
}
}else{
$view['error'] = validation_errors();
}
if(array_key_exists('error', $view)){
$view['admin_view'] = "admin/add_books";
$this->load->view('layouts/admin_layout', $view);
}else{
//Insert the record
}

unable to upload multiple image in cake php

I am creating a form and trying to upload multiple image .All thing right with single image . when I am trying to upload multiple image,Then I receive only one image in output .
Here is my View file.
<div class="from-control-div">
<?php echo $this->Form->create('Post', array('type' => 'file','id'=>'unitform','class'=>'form-horizontal','role'=>'form','url' => array('controller' => 'posts', 'action' => 'savepost')));?>
<div class="from-div-bottom">
<div class="form-group">
<label class="col-sm-4 control-label">File Upload</label>
<div class="col-sm-6" id="more-files">
<?php echo $this->Form->input('files.',array('type'=>'file','label' => false,'placeholder' => 'Upload images','id'=>"inputFile",'multiple','onchange'=>'readURL(this)'));?>
<!--<div id="fileList"></div>-->
</div>
<a class="col-sm-2 pull-right" style="font-weight:bold;" id="add-more"><i class="fa fa-plus"></i> Add More</a>
</div>
</div>
</form>
After this here is my controller.If I print print_r($data); then output is single array. No multiple array receive .Any help for me
Array ( [0] => Array ( [name] => download.jpg [type] => image/jpeg [tmp_name] => /tmp/phpX3Oy32 [error] => 0 [size] => 12988 ) )
public function savepost() {
if (count($this->request->data) > 0) {
$fileNames = '';
if (isset($this->request->data['Post']['files']) && count($this->request->data['Post']['files']) > 0) {
$data=$this->request->data['Post']['files'];
print_r($data);
$fileNames = array();
foreach ($this->request->data['Post']['files'] as $filedata) {
if(isset($filedata["name"]) && ($filedata["name"] !='')){
$upload_dir = FILE_UPLOAD_PATH;
$original = explode('.', $filedata["name"]);
$extension = array_pop($original);
$newname = time() . '.' . $extension;
if (file_exists($upload_dir . $newname)) {
unlink($upload_dir . $newname);
}
if (move_uploaded_file($filedata["tmp_name"], $upload_dir . $newname)) {
$fileNames[] = $newname;
print_r($fileNames);
}
}
}
}
}
}
public function savepost() {
if(isset($this->request->data['multifiles'])){
$file_name_all="";
for($i=0; $i<count($this->request->data['multifiles']); $i++){
if(!empty($this->request->data['multifiles'][$i]['name'])){
$file = $this->request->data['multifiles'][$i];
$file['name'] = time() . '-' . str_replace(' ', '_', $file['name']);
$uploadPath = WWW_ROOT . 'img/ ';
$fileName = $file['name'];
$uploadFile = $uploadPath.$fileName;
$file_name_all.= $file['name'].",";
if($file['name']){
move_uploaded_file($file['tmp_name'], $uploadFile);
}
}
}
}
}
in my code it is working.

cakephp: add filter to a report from dropdown list

I have a report to generate as a view and as an excel file. I am bale to show all its rows in both. The user needs to filter data based on a date field "end_date". In my view, I put this:
<?php
$options = array();
$options[0] = 'All';
$options[1] = 'Due last 6 months';
$options[2] = 'Due current month';
$options[3] = 'Due next 3 months';
$options[4] = 'Due next 6 months';
$options[5] = 'Due next 12 months';
?>
<div class="row">
<?= $this->Form->create() ?>
<fieldset>
<div class="col-sm-2"><?= $this->Form->input('select_period', array('options' => $options)); ?></div>
<div class="col-sm-2" style="padding-top:25px;"><?= $this->Form->button('Search', ['type' => 'submit', 'class' => 'btn btn-primary']); ?></div>
</fieldset>
<?= $this->Form->end() ?>
</div>
in my controller, I use this function:
public function reportReplacement()
{
$assetsAssignations = $this->AssetsAssignations->find()
->contain([
'AssetStatuses',
'Assets' => [
'AssetTypes'
],
'Clients' => [
'ClientTypes'
],
])
->order([
'AssetTypes.name' => 'asc',
]);
$filter = $this->Filter->prg($assetsAssignations);
$_filename = "xls_report_replacement_" . date('Ymd');
$this->set(compact('assetsAssignations', '_filename'));
}
I tried to put this in my controller intialize, but it did not work:
if ($this->request->param('action') == 'reportReplacement') {
$select_period = $this->request->query('select_period'); // I want to get the selected [0], [1], etc.. when I debug, I always get null.
I also failed to fin where I have to put the option as a condition in my queries like:
if option[1], then 'end_date' >= (TODAY-6 months) AND 'end_date' <= TODAY;
if option[2], then 'end_date' = TODAY(month);
if option[1], then 'end_date' >= TODAY AND 'end_date' <= (TODAY+3 months);
etc.
any help please ?
Thanks to Greg, I found the solution:
in the view:
<?php
$options = array();
$options[0] = 'Due last 6 months';
$options[1] = 'Due current month';
$options[2] = 'Due next 3 months';
$options[3] = 'Due next 6 months';
$options[4] = 'Due next 12 months';
?>
<div class="row">
<?= $this->Form->create() ?>
<fieldset>
<div class="row">
<div class="col-xs-3"><?= $this->Form->input('select_period_id', ['options' => $options, 'empty' => true, 'label' => __('Select Period')]) ?></div>
<div class="col-sm-2" style="padding-top:25px;"><?= $this->Form->button(__('Submit')) ?></div>
</div>
</fieldset>
<?= $this->Form->end() ?>
</div>
in the controller:
use Cake\I18n\Time;
and in the function:
$data = $this->request->data;
$select_period = $this->request->data('select_period_id');
$today = Time::now()->format('Y-m-d');
$second_date = Time::now();
$assetsAssignations = $this->AssetsAssignations->find()
->contain(['Assets']);
if($this->request->is(['patch', 'post', 'put']))
{
if ($select_period == 0) {
$second_date = $second_date->modify('-6 months');
$second_date = $second_date->format('Y-m-d');
$assetsAssignations->where([
'end_date >=' => $second_date,
'end_date <=' => $today
]);
} elseif ($select_period == 1) {
$second_date = $second_date->modify('1 month');
$second_date = $second_date->format('Y-m-d');
$assetsAssignations->where([
'end_date >=' => $today,
'end_date <=' => $second_date
]);
} elseif ($select_period == 2) {
$second_date = $second_date->modify('3 months');
$second_date = $second_date->format('Y-m-d');
$assetsAssignations->where([
'end_date >=' => $today,
'end_date <=' => $second_date
]);
} elseif ($select_period == 3) {
$second_date = $second_date->modify('6 months');
$second_date = $second_date->format('Y-m-d');
$assetsAssignations->where([
'end_date >=' => $today,
'end_date <=' => $second_date
]);
} elseif ($select_period == 4) {
$second_date = $second_date->modify('12 months');
$second_date = $second_date->format('Y-m-d');
$assetsAssignations->where([
'end_date >=' => $today,
'end_date <=' => $second_date
]);
}
}
$this->set(compact('assetsAssignations'));
}

FullCalendar in cakePHP 3.0 not displaying events on calendar

I am upgrading to cakePHP 3.0 and have almost all of the functionality of the FullCalendar plugin working except I can't get any events to populate on the calendar. I am not getting anymore error messages, which makes this difficult to solve. My controller method looks like this:
public function feed($id=null)
{
$this->request->allowMethod(['get']);
$this->layout = "ajax";
$vars = $this->params['url'];
$conditions = ['conditions' => ['UNIX_TIMESTAMP(start) >=' => $vars['start'], 'UNIX_TIMESTAMP(start) <=' => $vars['end']]];
$events = $this->Events->find('all', $conditions);
foreach($events as $event) {
if($event->all_day == 1) {
$allday = true;
$end = $event->start;
} else {
$allday = false;
$end = $event->end;
}
$data[] = array(
'id' => $event->id,
'title'=>$event->title,
'start'=>$event->start,
'end' => $end,
'allDay' => $allday,
'url' => Router::url('/') . 'full_calendar/events/view/'.$event->id,
'details' => $event->details,
'className' => $event->event_type->color
);
}
$this->set("json", json_encode($data));
}
My View is :
<?php
/*
* View/FullCalendar/index.ctp
* CakePHP Full Calendar Plugin
*
* Copyright (c) 2010 Silas Montgomery
* http://silasmontgomery.com
*
* Licensed under MIT
* http://www.opensource.org/licenses/mit-license.php
*/
?>
<div class="page-width">
<script type="text/javascript">plgFcRoot = "/<site name>/" + "full_calendar"; console.log(plgFcRoot);</script>
<?php
echo $this->Html->script(['/full_calendar/js/jquery-1.5.min', '/full_calendar/js/jquery-ui-1.8.9.custom.min', '/full_calendar/js/fullcalendar.min', '/full_calendar/js/jquery.qtip-1.0.0-rc3.min', '/full_calendar/js/ready']);
echo $this->Html->css('/full_calendar/css/fullcalendar');
?>
<div class="Calendar index">
<div id="calendar"></div>
</div>
<div class="actions">
<ul>
<li><?= $this->Html->link(__('New Event', true), ['controller' => 'events', 'action' => 'add']) ?></li>
<li><?= $this->Html->link(__('Manage Events', true), ['controller' => 'events']) ?></li>
<li><?= $this->Html->link(__('Manage Events Types', true), ['controller' => 'event_types']) ?></li>
</ul>
</div>
</div>
My ready.js is:
/*
* webroot/js/ready.js
* CakePHP Full Calendar Plugin
*
* Copyright (c) 2010 Silas Montgomery
* http://silasmontgomery.com
*
* Licensed under MIT
* http://www.opensource.org/licenses/mit-license.php
*/
// JavaScript Document
$(document).ready(function() {
// page is now ready, initialize the calendar...
$('#calendar').fullCalendar({
header: {
left: 'title',
center: '',
right: 'today agendaDay,agendaWeek,month prev,next'
},
defaultView: 'month',
firstHour: 8,
weekMode: 'variable',
aspectRatio: 2,
editable: false,
events: plgFcRoot + "/events/feed",
eventRender: function(event, element) {
element.qtip({
content: event.details,
position: {
target: 'mouse',
adjust: {
x: 10,
y: -5
}
},
style: {
name: 'light',
tip: 'leftTop'
}
});
},
eventDragStart: function(event) {
$(this).qtip("destroy");
},
eventDrop: function(event) {
var startdate = new Date(event.start);
var startyear = startdate.getFullYear();
var startday = startdate.getDate();
var startmonth = startdate.getMonth()+1;
var starthour = startdate.getHours();
var startminute = startdate.getMinutes();
var enddate = new Date(event.end);
var endyear = enddate.getFullYear();
var endday = enddate.getDate();
var endmonth = enddate.getMonth()+1;
var endhour = enddate.getHours();
var endminute = enddate.getMinutes();
if(event.allDay == true) {
var allday = 1;
} else {
var allday = 0;
}
var url = plgFcRoot + "/events/update?id="+event.id+"&start="+startyear+"-"+startmonth+"-"+startday+" "+starthour+":"+startminute+":00&end="+endyear+"-"+endmonth+"-"+endday+" "+endhour+":"+endminute+":00&allday="+allday;
$.post(url, function(data){});
},
eventResizeStart: function(event) {
$(this).qtip("destroy");
},
eventResize: function(event) {
var startdate = new Date(event.start);
var startyear = startdate.getFullYear();
var startday = startdate.getDate();
var startmonth = startdate.getMonth()+1;
var starthour = startdate.getHours();
var startminute = startdate.getMinutes();
var enddate = new Date(event.end);
var endyear = enddate.getFullYear();
var endday = enddate.getDate();
var endmonth = enddate.getMonth()+1;
var endhour = enddate.getHours();
var endminute = enddate.getMinutes();
var url = plgFcRoot + "/events/update?id="+event.id+"&start="+startyear+"-"+startmonth+"-"+startday+" "+starthour+":"+startminute+":00&end="+endyear+"-"+endmonth+"-"+endday+" "+endhour+":"+endminute+":00";
$.post(url, function(data){});
}
})
});
Any help in this matter would be greatly appreciated.
Sometimes I get this error in the console, but not every time:
GET http://localhost//full_calendar/events/feed?start=1433052000&end=1436076000&_=1433266131989 404 (Not Found)
I just solved my issue. I used a process of elimination and found that the conditions array that I had was set up incorrectly for cakePHP 3.0, so it was a cake issue. Instead of
CakePHP 2.x Syntax
$conditions = array('conditions' => array('UNIX_TIMESTAMP(start) >=' => $vars['start'], 'UNIX_TIMESTAMP(start) <=' => $vars['end']));
$events = $this->Event->find('all', $conditions);
it is:
CakePHP 3.x Syntax
$conditions = ['UNIX_TIMESTAMP(start) >=' => $vars['start'], 'UNIX_TIMESTAMP(start) <=' => $vars['end']];
$events = $this->Events->find('all', $conditions)->contain(['EventTypes']);
There isn't a conditions setting in the array, you just set the conditions which I got from this example in the cakePHP documentation:
$this->loadModel('Articles');
$recentArticles = $this->Articles->find('all', [
'limit' => 5,
'order' => 'Articles.created DESC'
]);

WordPress WP_Query showing only first element in the array

I am currently learning on WordPress plugin development and I am trying to build a short code for my plugin
my plugin is basically a custom post type called property which have 3 meta data boxs in it
price location and date of construction
and one taxonomy called property type which be setted at the backend with rent or sale
all of this works and if you put them in wordpress they will work
But my shortcode file does work properly the loop on the WP_Query should return all the post which I have made but instead its returning only the first element found in the WP_Query
Can anyone guide me or fix where I have mistaken please
thanks all
now my short code file name is: properties_post_type_shortcode.php
My plugin file name is: properties_post_type.php
code for properties_post_type_shortcode.php
<?php
add_shortcode('land_properties',function(){
$loop = new WP_Query(
array(
'post_type' => 'property_post',
'orderby' => 'title'
)
);
if ($loop->have_posts()){
$output = '<ul class="land_properties_list">';
$i=0;
while( $loop->have_posts() ){
$loop->the_post();
$meta=get_post_meta(get_the_id(),'' );
$output= '
<li>
<a href="' .get_permalink() . '">
' . get_the_title() . ' | '.
$meta['property_price'][0]. " " .
$meta['property_location'][0]. " " .
$meta['property_date'][0]. " " .
'
</a>
<div>' . get_the_excerpt() . '</div>
</li>
';
}
}
else {
$output="No lands added";
}
// $loop->wp_reset_postdata();
return $output;
});
code for properties_post_type.php
<?php
/*
* Plugin Name: properties_post_type
* Plugin URI: Have not be set yet
* Description: this plugin allow you to create custom post type property which you can be modified and edited
* Version: 1.0
* Author: Muhab Alwan
* Author URI: https://www.facebook.com/HaaaB
* License: A "Slug" license name e.g. GPL2
*/
class PROP_POST_TYPE{
//default contructor
public function __construct()
{
$this->register_post_type();
$this->taxonomies();
$this->metaboxes();
}
public function register_post_type()
{
$args= array(
'labels' => array(
'name'=> 'Properties',
'singular_value' => 'Property',
'add_new' => 'Add New Property',
'add_new_item' => 'Add New Property',
'edit_items' => 'Edit_Items',
'new_item' => ' Add New Items',
'view_item'=> 'View Item',
'search_items' => 'Search Items',
'not_found' => 'No Property Found',
'not_found_in_trash' => 'No Property Found In Trash'),
'query_var' =>'properties',
'rewrite' => array(
'slug' => 'property/'),
'public' => true,
'menu_position' => 80, // set postion in the backend menu
'menu_icon' => admin_url(). 'images/media-button-other.gif', // define an image for the prop
'supports' => array(
'title',
//'editor',
'excerpt',
//'custom-fields' when we need user to build their own meta box Not required in project
) // specify what wordpress types are custom post type support
);
register_post_type('property_post', $args );
}
public function taxonomies()
{
$taxonomies = array();
$taxonomies['property_type'] = array(
'hierarchical' => true,
'query_var' => 'movie_genere',
'rewrite' => array('slug' => 'prop/type'
),
'labels' => array(
'name'=> 'Properties Type',
'singular_value' => 'Property Type',
'add_new' => 'Add New Property Type',
'add_new_item' => 'Add New Property Type',
'edit_items' => 'Edit Properties Type',
'new_item' => ' Add New Properties Type',
'view_item'=> 'View Property Type',
'search_items' => 'Search Properties Type',
'popular_items' => 'Popular Properties Type',
'separate_items_with_comments' => 'Separate Property Type With Comments',
'add_or_remove_items' => 'Add Or Remove Properties Type',
'choose_from_most_used' => 'Choose From Most Used Properties Type'
)
);
$this-> register_all_taxonomies($taxonomies); // register all taxonomies build in this plugin
}
public function register_all_taxonomies($taxonomies)
{
// foreach is for registering many taxonomy
foreach ($taxonomies as $name=> $arr)
{
//register ( what the taxonomies name, array of the object type that we register ex post or page
register_taxonomy($name,array('property_post'),$arr );
}
}
public function metaboxes()
{
// FIRST PRICE META BOX
add_action('add_meta_boxes', function(){
//css id, title, cb func, page, priority level, call back func argum
add_meta_box('property_price','Property Price', 'property_price','property_post');
add_meta_box('property_location','Property Location', 'property_location','property_post');
add_meta_box('property_date','Date Of Construction', 'property_date','property_post');
});
//PRICE PROP
function property_price($post){
$price_length = get_post_meta($post->ID,'property_price', true);
?>
<p>
<label for="property_price"> :</label>
<input type="number" pattern="[0-9]+" size="50" class="widfat" name="property_price" id="property_price" value="<?php echo esc_attr($price_length)?>" /> </p>
<?php
}
add_action('save_post', function($id){
if ( isset ($_POST['property_price']))
{
update_post_meta(
$id,'property_price',
strip_tags($_POST['property_price'])
);
}
});
// LOCATIO PROP
function property_location($post){
$location_length = get_post_meta($post->ID,'property_location', true);
?>
<p>
<label for="property_location"> :</label>
<input type="text" class="widfat" name="property_location" id="property_location" value="<?php echo esc_attr($location_length)?>" /> </p>
<?php
}
add_action('save_post', function($id){
if ( isset ($_POST['property_location']))
{
update_post_meta(
$id,'property_location',
strip_tags($_POST['property_location'])
);
}
});
function property_date($post){
$dof_length = get_post_meta($post->ID,'property_date', true);
?>
<p>
<label for="property_date"> :</label>
<input type="date" class="widfat" name="property_date" id="property_date" value="<?php echo esc_attr($dof_length)?>" /> </p>
<?php
}
add_action('save_post', function($id){
if ( isset ($_POST['property_date']))
{
update_post_meta(
$id,'property_date',
strip_tags($_POST['property_date'])
);
}
});
//third date of construction metaboxes
}
}
// initialization essential to build a cust post
add_action('init', function(){
new PROP_POST_TYPE();
include dirname(__FILE__). '/properties_post_type_shortcode.php';
});
To query all posts, add the following to the args of WP_Query:
'posts_per_page' => -1
Your code:
$loop = new WP_Query( array(
'post_type' => 'property_post',
'orderby' => 'title',
'posts_per_page' => -1
) );

Resources