i have a form that insert loop data. the problem is even i don't insert new data on my form, my database still adding a new one.i can add more one data in same data, but when create new data after first one,get me twice data with empty value.
here is my code
Controller
$doc_number = $_POST['doc_number'];
$closedby = $_POST['closedby'];
$reasonclose = $_POST['reasonclose'];
$description = $_POST['description'];
for($i=0;$i<count($closedby);$i++) {
$solved = array(
'DOC_NUMBER' => $doc_number,
'LOB' => $closedby,
'REASON' => $reasonclose,
'DESCRIPTION' => $description,
'CREATE_DATE' => $dateop,
'ID_SOLVED' => ++$num
);
$this->db->insert('NEWS_EVENT_SOLVED_TAB',$solved);
var_dump($solved);
}
VIEW
<div class="controls" style="margin-left: 70px;">
<input id="idf" type="hidden" value="<?php echo $num;?>" />
<input id="idf" type="hidden" value="1" />
<div id="divSolved"></div>
<button type="button" onclick="addLob(); return false;">Add LOB</button>
</div>
JAVASCRIPT
function addLob() {
var idf = $("#idf").val();
var stre = "<p id='srow" + idf +"'>"+
"<select id='closedby_"+idf+"' name='closedby[]' class='form-control span3'>"+
"<option value=''>Choose One LOB</option>"+
"<option value='alkes'>Alkes</option>"+
"<option value='bd'>BD</option>"+
"<option value='cosmetic'>Cosmetic</option>"+
"<option value='feed'>Feed</option>"+
"<option value='food'>Food</option>"+
"<option value='import'>Import</option>"+
"<option value='logistic'>Logistic</option>"+
"<option value='pharma'>Pharma</option>"+
"<option value='purchasing'>Purchasing</option>"+
"<option value='qa'>QA</option>"+
"</select>"+
"<select id='reasonclose_"+idf+"' name='reasonclose' class='form-control span3'>"+
"<option value=''>Choose One Reason</option>"+
"<option value='Claim Insurance'>Claim Insurance</option>"+
"<option value='Claim Principal'>Claim Principal</option>"+
"<option value='Claim Transporter'>Claim Transporter</option>"+
"<option value='Sample'>Sample</option>"+
"<option value='Sold To Customer'>Sold To Customer</option>"+
"</select>"+
"<textarea rows='2' id='description_"+idf+"' name='description' placeholder='Keterangan'/>"+
"<a href='#' style='color:#3399FD;' onclick='hapusElemen(\"#srow" + idf + "\"); return false;'><img alt='' src='<?php echo themeUrl(); ?>images/delete.png'></a>"+
"</p>";
$("#divSolved").append(stre);
idf++;
$("#idf").val(idf);
}
function hapusElemen(idf) {
$(idf).remove();
}
function confirm(){
var isi = '<div align="" class="text-">Please wait while processing...<br /><img alt="" src="<?php echo themeUrl(); ?>img/ajax_loader.gif" align=""></div>';
$('.modal-body').html(isi);
var modalWidth = 300;
var left = (screen.availWidth - (modalWidth * 2));
$('button.close').hide();
$('#myModal').css({'width':modalWidth+'px','left':left+'px'}).modal({backdrop:'static',keyboard:false,show:true});
var hotdata = $('#productclose').handsontable('getInstance');
hstable = JSON.stringify({'data':hotdata.getData()});
//alert(lob);
for(var i=1; i<$('#idf').val(); i++) {
$.post('<?php echo base_url('report/news_event/confirmed'); ?>',{
doc_number : $('#id_number').val(),
closedby : $('#closedby_'+i).val(),
reasonclose : $('#reasonclose_'+i).val(),
description : $('#description_'+i).val(),
itemdata : hstable
//datenumber : $('#reminder_date').val()
},function() {
//alert($('#closedby').val());
//location.reload();
});
}
}
The issue you've got is that when you submit, even if there's nothing added, is that there will still be one $_POST['closedby'] record, but the value might be blank.
In the for loop, you should check to see if $_POST['closedby'] is empty/blank or generally the default for the options. If it is, then don't do the insert. Something like:
if (!empty($_POST['closedby'][$i])
{
// insert code
}
As a side note, you should use models to interact with your database, and have the controller call functions in the model.
Related
I have 2 drop downs, just for simplicity let's say they are Country / States.
<select id="country_id" name = "country_id">
<option value="">Select...</option>
<?php foreach ($countries as $country): ?>
<option value="<?php echo $country->id; ?>" <?php if (null !== set_value("country_id") && set_value("country_id") == $country->id) : echo ' selected '; ?>>$country->name;
<?php endforeach?>
</select>
<select id="state_id" name = "state_id">
<option value="">Select...</option>
</select>
<input type="file" name="attachment_id" value="" />
What I do is when the country is selected I populate the states. This I do using AJAX and ".change" and this works well
The problem I'm having is when I do form_validation and
$this->form_validation->run() == FALSE
Then I reload all controls using set_value, which does work for the first drop down (the countries) just fine, however the second drop down stays empty( as there was no ".change" triggered on the "country_id" to populate "state_id".
Similarly I am asked to re-attach the file
So what I need and is not working is after form_validation fail to
Load up second drop down with data => RESOLVED see below with .trigger event
Select the previous selection int he second drop down => ALMOST RESOLVED however only if I use alert :)
The attachment should still stay attached until form is dismissed or committed successfully => NOT RESOLVED
I feel like I need to manually trigger the data change to get (1) but in my case I have a foreach (see above) where I just add lines and if the selection is the same I simply set is as "selected" but nothing happens after.
Here is the AJAX part
<script>
$(document).ready(function(){
$("#country_id").change(function(){
$.ajax({
url:"<?php echo base_url(); ?>location/getCountries",
data: {country_id: $(this).val()},
type: "POST",
success: function(data){
$("#state_id").html(data);
$("#state_id").val(null);
}
});
});
<?php if (!empty(set_value('country_id'))) : ?>
var value = "<?php echo set_value('country_id'); ?>";
$('#country_id').val(value);
$('#country_id').trigger('change');
<?php endif; ?>
<?php if (!empty(set_value('state_id'))) : ?>
var value = "<?php echo set_value('state_id'); ?>";
//without this alert the selection doesn't work
alert(value);
$('#state_id').val(value);
$('#state_id').trigger('change');
<?php endif; ?>
});
</script>
So I am getting the values saved only if I use an alert. This seems to be an asynchronous execution where the selection of second drop down is done before it gets populated, so the last thing to do is to figure out how to wait.
Still to do the attachment part
Thanks in advance!
Add this code at the end of view page
For country dropdown
<?php if (!empty(set_value('country_id'))) : ?>
<script type="text/javascript">
var value = "<?php echo set_value('country_id'); ?>";
$('select[name="country_id"]').find('option[value="'+value+'"]').attr("selected",true);
</script>
<?php endif; ?>
For state dropdown
<?php if (!empty(set_value('state_id'))) : ?>
<script type="text/javascript">
var value = "<?php echo set_value('state_id'); ?>";
$('select[name="state_id"]').find('option[value="'+value+'"]').attr("selected",true);
</script>
<?php endif; ?>
Follow the below points
1) For select tag, use set_select(), like this
<select name="myselect">
<option value="one" <?php echo set_select('myselect', 'one', TRUE); ?> >One</option>
<option value="two" <?php echo set_select('myselect', 'two'); ?> >Two</option>
<option value="three" <?php echo set_select('myselect', 'three'); ?> >Three</option>
</select>
2) If the form validation failed, call your ajax function to set second drop down.
3) For attachment, Whatever result of the form validation, first upload the image and keep the image path in session variable. After successful form validation, save the data into database and destroy the session variable.
edited >>>
**html**
<?php
if (isset($edit) && !empty($edit)) { //while editing
$StateID = $edit['StateID'];
$CountryID = $edit['CountryID'];
} else { // while adding
$StateID = set_value('StateID');
$CountryID = set_value('CountryID');
} ?>
<div class="col-3">
<div class="form-group">
<label class="mb-0">Country</label>
<select class="form-control Country" id="country" name="CountryID" data_state_value="<?php echo $StateID; ?>" >
<option value="">Select Country</option>
<?php
foreach ($country as $row) {
$selected = ($row->id == $CountryID) ? 'selected' : '';
echo '<option value="' . $row->id . '"' . $selected . '>' . $row->country_name . '</option>';
}
?>
</select>
<span class="text-danger font9"><?php echo form_error('CountryID'); ?></span>
</div>
</div>
<div class="col-3">
<div class="form-group">
<label class="mb-0">State</label>
<select class="form-control State" id="State" name="StateID">
</select>
<span class="text-danger font9"><?php echo form_error('StateID'); ?></span>
</div>
</div>
**script**
$(document).on('change', '.Country', function () {
var country_id = $(this).val();
var state_id = $(this).attr('data_state_value');
url = $("body").attr('b_url');
$.ajax({
url: url + "Education/fetch_state",
method: "POST",
data: {
country_id: country_id,
state_id: state_id
},
success: function (res) {
var response = $.parseJSON(res);
$('#State').html('<option value="">Select State</option>' + response.view);
$('.State').trigger('change');
}
});
});
$('.Country').trigger('change');
**controller**
public function fetch_state() {
$data = array();
if (isset($_POST['country_id']) && !empty($_POST['country_id'])) {
$states = $this->Location_model->fetch_state($this->input->post('country_id')); // array of states
$view = array();
if (!empty($states)) {
foreach ($states as $val) {
$selected = (isset($_POST['state_id']) && !empty($_POST['state_id']) && $_POST['state_id'] == $val['id']) ? 'selected' : '';
$view[] = "<option value='" . $val['id'] . "'" . $selected . ">" . $val['states_name'] . "</option>";
}
$data['view'] = $view;
$data['status'] = 0;
} else {
$data['status'] = 0;
$data['view'] = '<option value="">No State Found</option>';
}
} else {
$data['status'] = 0;
$data['view'] = '<option value="">Select State</option>';
}
echo json_encode($data);
}
I want to fetch the corresponding value of my dropdown the image below shows the form and the database. the table was inside the javascript and Iam having a dificult time in figuring out this problem. please help me how to solve this problem... Thank you very much in advance...
Database
forms entry
My Controller
function getFeetypeEndDate() {
$feetype_id = $this->input->get('feety_id[]');
$data = $this->feegroup_model->getFeetypeByEndDate($feetype_id);
echo json_encode($data);
}
My Model
public function get($id = null) {
$this->db->select()->from('feetype');
$this->db->where('is_system', 0);
if ($id != null) {
$this->db->where('id', $id);
} else {
$this->db->order_by('id');
}
$query = $this->db->get();
if ($id != null) {
return $query->row_array();
} else {
return $query->result_array();
}
}
My Javascript in the View Section
<script>
$(document).ready(function (){
$("body").on('click', '.btn-add-more', function (e) {
e.preventDefault();
var amount = $("#amount").val();
var penalty = $("#penalty").val();
var $sr = ($(".jdr1").length + 1);
var rowid = Math.random();
var $html = '<tr class="jdr1" id="' + rowid + '">' +
'<td><span class="btn btn-sm btn-default">' + $sr + '</span><input type="hidden" name="count[]" value="'+Math.floor((Math.random() * 10000) + 1)+'"></td>' +
'<td><select id="feetype_id[]" name="feetype_id[]" class="form-control" >' +
'<?php foreach ($feetypeList as $feetype) { ?>' +
' <option value="<?php echo $feetype['id'] ?>" ' +
'<?php if (set_value('feetype_id[]') == $feetype['id']) { echo "selected =selected"; } ?>><?php echo $feetype['type'] ?></option> <?php $count++; } ?> </select></td>' +
'<td><input type="text" id="startDate" name="startDate" value="<?php echo date($this->customlib->getSchoolDateFormat($feetype->start_date), $this->customlib->dateyyyymmddTodateformat($feetype->start_date)); ?>" placeholder="Start Date" class="form-control input-sm"/></td>' +
'<td><input type="text" id="endDate" name="endDate" value="<?php echo date($this->customlib->getSchoolDateFormat($feetype->end_date), $this->customlib->dateyyyymmddTodateformat($feetype->end_date)); ?>" placeholder="End Date" class="form-control input-sm"/></td>' +
'<td><input type="text" name="amount_td[]" placeholder="Amount" class="form-control input-sm" value="'+amount+'"></td>' +
'<td><input type="text" name="penalty_td" placeholder="Penalty" class="form-control input-sm" value="'+penalty+'"></td>' +
'</tr>';
$("#table-details").append($html);
});
$("body").on('click', '.btn-remove-detail-row', function (e) {
e.preventDefault();
if($("#table-details tr:last-child").attr('id') != 'row1'){
$("#table-details tr:last-child").remove();
}
});
});
I've been trying to make an attendance management system in Laravel.
In the attendance view,when a checkbox is checked ,the controller function is supposed to increment the appropriate database column.
I've been having some issues.Here's my code:
views:
<div class="container">
<!--<div class="row">-->
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Take Attendance</div>
<h4><center>Teacher: {{ auth()->user()->name}}</center></h4>
<div class="form-inline">
#foreach ($second as $sec)
<br>
<div class = "form-group">
{{$sec->Roll }}
    
{{ $sec->Name}}
</div>
<div class = "form-group">
<!--{{Form::checkbox('agree') }}-->
<input tabindex="1" type="checkbox" value="{{$sec->Roll}}" name="" />
</div>
#endforeach
</div>
<br>
<form action ="report_generate&<?php echo $name ?>" method = "post" enctype = "multipart/form-data" >
<!--<input type = "hidden" name = "_token" value = "{{{ csrf_token() }}}"/>-->
<div class = "form-group">
<input type="submit" value= "Submit">
<center>Report</center>
</div>
</form>
</div>
</div>
</div>
Controller(for submit button):
public function report_generate($tabu)
{
$year = DB::table('sub')->select('Year')-
>where('sub.Subject_Name','=',$tabu)->get();
$sub_id = DB::table('sub')->select('Subject_Id')-
>where('sub.Subject_Name','=',$tabu)->get();
ob_start();
echo $year;
$output=ob_get_contents();
ob_end_clean();
if ( $output=='[{"Year":1}]')
{
$req = "first";
}
elseif ( $output=='[{"Year":2}]')
{
$req = "second";
}
elseif ( $output=='[{"Year":3}]')
{
$req = "third";
}
elseif ( $output=='[{"Year":4}]')
{
$req = "fourth";
}
$final = DB::table($req)->get();
//dd($final);
//$columns = Schema::getColumnListing($req);
//dd($sub_id);
ob_start();
echo $sub_id;
//dd($sub_id);
$va=ob_get_clean();
$va = stripslashes($va);
$txt = rtrim($va,"}]");
$txt = ltrim($txt,"[{Subject_Id:");
$txt = ltrim($txt,"Subject_Id:");
$txt = explode(":",$txt);
$txt = str_replace('"','', $txt);
//dd($txt[1]);
$columns = Schema::getColumnListing($req);
//dd($columns);
//dd($txt);
foreach ($columns as $col)
{
//dd("Y");
if($col == $txt[1])
{
$got=DB::table($req)->select($col)->get();
//dd($got);
foreach($got as $g)
{
//want to increment that cell value
}
}
}
}
Looks like your checkboxs are outside of the form divs which is an issue. You also seem to be skipping over the Laravel features, for example having a Sub Model you can call on, or using the Request facade. Also not sure why you're using ob for those string comparisons (might actually want to look at Switch for that long elseif block) Lastly, you might want to to use a raw DB statement to do the increments within a SQL query
DB::statement("UPDATE " . $table . " set " . $column . " to " . $column . " + 1 WHERE id IN (" implode(', ', $ids) . ')")
I wanted to change an input value based on the selection from a combobox in codeigniter. I tried to code it but theres nothing to be displayed.
Here is my code in my controller.....
function fill_info()
{
// retrieve the group and add to the data array
$group_id = $this->input->post('group_id');
$data = "0.00";
if($group_id)
{
$this->load-model('Base_amount_setting_model');
$baseamount = $this->Base_amount_setting_model->getbaseamount($group_id);
$data .= $baseamount;
echo $data;
}
else
{
echo $data;
}
}
And in my Base_amount_setting_model there is this method....
function getbaseamount($group_id)
{
$this->db->where('group_id',$group_id);
$baseamount = $this->db->get('base_amount_setting')->row()->amount;
if($baseamount -> num_rows() == 1)
{
return $baseamount->result();
}
}
And there in my view the ajax looks like this.....
<script>
$(document).ready(function()
{
$("#group_id").change(function()
{
var group_id = $("#group_id").val();
$.ajax({
type : "POST",
url : "<?php echo base_url('payment/fill_info'); ?>",
data : "group_id=" + group_id,
success: function(data)
{
$("#base_amount").html(data);
}
});
});
});
</script>
and finally my form is like this...
<div class="control-group">
<label class="control-label" for="select01">Group Id </label>
<div class="controls">
<select class="chzn-select" name="group_id" id="group_id" placeholder="Group Id" value="<?php echo $group_id; ?>">
<option></option>
<?php
if (count($groups)) {
foreach ($groups as $list) {
echo "<option value='". $list['group_id'] . "'>" . $list['group_name'] . "</option>";
}
}
?>
</select>
<label for="int" class="err"><?php echo form_error('group_id') ?></label>
</div>
<input class="input-xlarge disabled" id="base_amount" name="base_amount" type="text" placeholder="Base Amount" disabled="">
<input class="input-xlarge disabled" id="total_members" type="text" placeholder="Total Members" disabled="">
</div>
Thank You!
change this $("#base_amount").html(data);
to $("#base_amount").val(data);
Actually if you get your value after ajax hit in data object
then only change this :
$("#base_amount").html(data);
to
$("#base_amount").val(data);
Actually .html replce the html not change the value.
i'm really curious - but i think your model doesnt return anything
try the following
function getbaseamount($group_id)
{
$query = $this->db
->where('group_id',$group_id)
->get('base_amount_setting');
if ($query->num_rows() == 1)
{
$obj = $query->row();
return $obj->amount;
}
}
and as others suggested
change your script code to
$("#base_amount").val(data);
and your controller function should look like
function fill_info()
{
// retrieve the group and add to the data array
$group_id = $this->input->post('group_id');
$data = "0.00";
if($group_id)
{
$this->load-model('Base_amount_setting_model');
$baseamount = $this->Base_amount_setting_model->getbaseamount($group_id);
echo $baseamount;
}
else
{
echo $data;
}
}
I have created a custom post "news" in Wordpress and I want to search posts and paginate them without page reload.
I.m using $wpdb class and it is now working fine but when I try to do an ajax call I don't get any results.
Here is the error I am getting:
<b>Notice</b>: Undefined variable: parent_slug in
<b>C:\xampp\htdocs\website\wp-content\themes\website\includes\news\output_more-news.php</b> on line <b>14</b>
<b>Fatal error</b>:
Call to undefined function get_terms() in <b>C:\xampp\htdocs\website\wp-content\themes\website\includes\news\output_more-news.php</b> on line <b>15</b>
here's my ajax code:
jQuery( document ).ready(function() {
jQuery('#news_form').on('submit', function(e) {
var
that = jQuery(this),
url = "http://localhost/website/wp-content/themes/website/includes/news/output_more-news.php",
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index,value){
var
that = jQuery(this),
name = that.attr('name'),
value = that.val();
data[name]= value;
console.log(data);
});
jQuery.ajax({
url: url,
type: type,
data: data,
beforeSend : function (){
//do something like loading gif
},
success: function(data){
alert("form submited");
console.log(data);
},
error:function(){
alert("error");
}
});//ajax call
e.preventDefault()
});
here's output_more-news.php
$search_term = "%" . strtolower($_POST['name_search'])."%";
if(!empty($_POST['archive-dropdown'])){
$archive_selected = $_POST['archive-dropdown'];
}else{
$archive_selected = "";
}
$taxonomy = ucfirst($parent_slug);
foreach(get_terms('news_categories') as $term){
if($term->slug == $parent_slug){
$term_ID = $term->term_id;
}
}
$home_url = get_home_url();
$site_directory_url = get_template_directory_uri();
$archive_selected = $_POST['archive-dropdown'];
$archive_selected = str_replace("$home_url","",$archive_selected );
$archive_selected = str_replace("?post_type=news","",$archive_selected );
$archive_date = preg_split("/[\/]+/",$archive_selected );
$archive_month = $archive_date[2];
$archive_year = $archive_date[1];
global $wpdb;
$more_news_query =
"
SELECT $wpdb->posts.ID
FROM $wpdb->posts
INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
AND $wpdb->term_taxonomy.taxonomy = 'news_categories'
AND $wpdb->term_taxonomy.term_id IN ($term_ID)
WHERE $wpdb->posts.post_title LIKE '$search_term'
";
if(!empty($archive_selected)){
$more_news_query .=
"
AND month($wpdb->posts.post_date) = '$archive_month'
AND year($wpdb->posts.post_date) = '$archive_year'
";
}
$more_news_query .=
"
AND $wpdb->posts.post_type = 'news'
AND $wpdb->posts.post_status = 'publish'
ORDER BY $wpdb->posts.post_date
";
$count_results = "SELECT COUNT(1) FROM (${more_news_query}) AS combined_table";
$total = $wpdb->get_var($count_results);
$items_per_page = get_option( 'posts_per_page' );
$paged = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
$offset = ( $paged * $items_per_page ) - $items_per_page;
$max_num_pages = ceil($total / $items_per_page);
$more_news = $wpdb->get_results( $more_news_query . " LIMIT ${offset}, ${items_per_page}" );
$prev_link = $paged - 1;
if($prev_link <= 0){
$prev_link = 1;
}
$nextlink = $paged + 1;
if($nextlink >= $max_num_pages){
$nextlink = $max_num_pages;
}
echo"<div class='panel-group' id='accordion'>
<div class='panel panel-default'>
<div class='panel-heading'>
<h4 class='panel-title''>
<a class='accordion-toggle' data-toggle='collapse' data-parent='#accordion' href='#collapseMore'>
<span>More News</span>
</a>
<a class='accordion-toggle' data-toggle='collapse' data-parent='#accordion' href='#collapseMore'>
<i class='pull-right fa fa-plus-circle' aria-hidden='true'></i>
</a>
</h4>
</div>";
echo "<div id='collapseMore' class='panel-collapse collapse '>";
echo "<div class='panel-body'>";
echo "<div class='search_bar clearfix'>";
echo "<div class='col-lg-10 col-md-9 col-sm-8 col-xs-7'>
<form id='news_form' method='post' action='' class='clearfix'>
<div class='form_fields_container col-md-7'>
<span class='btns cut_corner_btns news_search_label'>News</span><input placeholder='Search' type='text' name='name_search'>
<i class='fa fa-search' aria-hidden='true'></i>";
?>
</div>
<div class='form_fields_container select_container col-md-5'>
<span class="btns cut_corner_btns news_search_label"><?php echo strtoupper($parent_slug);?> archives</span>
<select name="archive-dropdown" >
<option value=""></option>
<?php wp_get_archives( array( 'news_categories' => $taxonomy, 'type' => 'monthly', 'format' => 'option', 'post_type'=>'news', 'show_post_count' => false ) ); ?>
</select>
</div>
</form>
</div>
<?php
echo "<div class='col-lg-2 col-md-3 col-sm-4 col-xs-5 news-pagination-container'>";
echo"<div class='news-pagination pull-right'>
<span>Page</span>
<a class='page-numbers current' href='$home_url/$parent_slug/news/?cpage=$paged'>$paged</a>
<span> of</span>
<a class='page-numbers' href='$home_url/$parent_slug/news/?cpage=$max_num_pages'>$max_num_pages </a>";
echo "<a class='prev page-numbers' href='$home_url/$parent_slug/news/?cpage=$prev_link'><i class='fa fa-angle-left' aria-hidden='true'></i></a>";
echo" <a class='next page-numbers' href='$home_url/$parent_slug/news/?cpage=$nextlink'><i class='fa fa-angle-right' aria-hidden='true'></i></a>";
echo "</div>";
echo "</div>";
echo "</div>";
if(!empty($total)) :
foreach($more_news as $news) {
$thumb_id = get_post_thumbnail_id();
$thumb_url_array = wp_get_attachment_image_src($news->ID, 'thumbnail-size', true);
$thumb_url = $thumb_url_array[0];
$date = get_the_date("Y-m-d ",$news->ID);
$title = get_the_title($news->ID);
$content = get_the_content($news->ID);
$content = substr($content,0,30);
$permalink = get_the_permalink();
echo"<div class='col-md-6 col-sm-12 col-xs-12 more_post_container'>";
echo"<div class='more_post_thumb col-xs-4'><img class='img-responsive' src='$thumb_url'/></div>";
echo"<div class='more_news_content col-xs-8'>
<p>$date</p>
<p class='color-$parent_slug '>$title</p>
<p class=''>$content...</p>
<a class='more_post_permalink' href='$permalink'>more</a>
</div>";
echo "</div>";
}
echo"</div>";
echo"</div>";
else:
echo "no results found!";
endif;
echo"<div id='response'></div>";
echo"</div>";
echo"</div>";
?>
Any help will be much appriciated.
Thanks in advance
You have 2 ways to resolve the error
Adding require '../../../wp-load.php'in output_more-news.php, which will manually load in WordPress corefiles, but its a bad way.
The correct way is documented here