'Ajax Load More' Plugin has installed on my website, i want to change Ordering
there is spacialfield in wp_posts Table On DB
But I can't how to set in on my posts
<option value="spacial" selected="selected">VIP (default)</option>
<option value="date">Date</option>
changed on :
plugins / ajax-load-more / admin / shortcode-builder / shortcode-builder.php
So it is :
<div class="inner half">
<label class="full"><?php _e('Order By', 'ajax-load-more'); ?>:</label>
<option value="spacial" selected="selected">VIP (default)</option>
<select class="alm_element" name="post-orderby" id="post-orderby">
<option value="date">Date</option>
<option value="title">Title</option>
<option value="name">Name (slug)</option>
<option value="menu_order">Menu Order</option>
<option value="author">Author</option>
<option value="ID">ID</option>
<option value="comment_count">Comment Count</option>
<option value="modified">Modified</option>
<option value="meta_value_num">meta_value_num</option>
</select>
</div>
But Nothing has changed and posts don't sort as i want
Shortcode Output on Admin Panel > Ajax Load More > Shortcode Builde :
[ajax_load_more post_type="post" orderby="spacial"]
Where should i put 'shortcode-builder' Code ?
------------------- Updata -------------------
You mean Admin Panel > Apearacne > Editor > main Page (Home page)
I can found :
echo do_shortcode('[ajax_load_more category__not_in=1 '.$query.' button_label="More Posts" orderby="title" order="DESC" posts_per_page="20" ]');
When i change orderby To spacial it doesn't works
Also I try :
<?php
$cat = get_category( get_query_var( 'cat' ) );
$category = $cat->slug;
if (!empty ($category))
$query .= ' category="'.$category.'" ';
if (isset ($_GET["province"]) && !empty($_GET["province"]))
$query .= ' meta_key="province" meta_value="'.$_GET["province"].'" ';
if (isset ($_GET["city"]) && !empty($_GET["city"]))
$query .= ' meta_key="city" meta_value="'.$_GET["city"].'" ';
$query .= ' ORDER BY SPACIAL DESC';
echo do_shortcode('[ajax_load_more category__not_in=1 '.$query.' button_label="More Posts" posts_per_page="20" ]');
?>
You can only order by custom field value not a field in the wp.posts table (I believe).
https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
If spacial was a custom field.
[ajax_load_more post_type="post" orderby="meta_value" meta_key="spacial"]
Related
I have a select2, which lists all items of a database table. One of these items is already selected. In edit mode, how can I show the already selected item and list the rest of the items?
IN CONTROLLER:
$offertaheader = Offertaheader::find($id_offertaheader);
$clients = Client::all()->where('visibility',1)
->sortBy('nome');
return view('offertas.edit',compact('offertaheader','clients'));
IN VIEW BLADE:
<select class="form-control select2" name="id_cliente" style="width: 100%">
<optgroup label="<?php echo htmlentities(utf8_encode('CLIENTE'), 0, "UTF-8"); ?>">
<option></option>
#foreach($clients as $client)
<option value="{{$client->id}}" {{ (old('id_client', $client->id) == ($client ? $client->id : '') ? ' selected' : '') }}>{{$client->nome}}</option>
#endforeach
</select>
I want that the already selected item must be shown and at the same time the user can change it in the blade. I prefer to avoid front-end codings like jquery or ajax.
You can update using sync method, sth like this,
public function upate()
{
$todo = Todo::findOrFail($id);
$data = $request->all();
$todo->update($data);
$users = $request->users;
$users = User::find($users);
$todo->users()->sync($users);
return response()->json("success",200);
}
first view page to forward
<div class="row">
<div class="col-lg-12 col-xs-12 col-sm-12 col-md-12">
<select name="forwardto[]" class="form-control">
<option value="">Select</option>
<?php foreach($userlist as $row):?>
<option value="<?php echo $row['cid']?>">
<?php echo $row['FirstName'].$row['MiddleName'].$row['LastName']?>
</option>
<?php endforeach;?>
</select>
</div>
Inside Controller
function forward($param1='', $param2=''){
$data1['message']='';
$data['ForwarderId']=$this->session->userdata('cid');
$data['ForwarderName']=$this->session->userdata('name');
$data['Designation']=$this->session->userdata('position'); /* title ..I have created Designation in Stmessage table */
$data1['RecieverId']=implode(', ', $_POST['forwardto']);
$Rcid = implode(" ", $data1);
$data['RecieverName']=$this->ag->name($Rcid);//this is not working
//ag->is agency model
$this->db->update('st_message', $data);
if($this->db->affected_rows()>0){
$dat['ReadStatus']='N';
$this->db->where('Id', $param1);
$this->db->update('st_message', $dat);
Inside model
public function name($Rcid)
{
$query=$this->db->query("SELECT CONCAT(e.FirstName, ' ',e.MiddleName, ' ', e. Lastname) as name, e.cid AS cid FROM bpas_user_profiles e
WHERE e.cid='".$Rcid."'");
if ($query->num_rows() > 0)
{
return $query->row();
} else {
return array();
}
}
Actually a data ,example 11112334 is selected and is passed via forwardto[] to controller.
But when I pass this $Rcid which related to forwardto[] as parameter to the model, it is not able to fetch.Actually I want to map number example 111323232 to name and update it in the table
I am stuck for 2 days, do you know how to show old data of select element in Laravel?
<select name="sexe" id="sexe" class="form-control">
<option value="">Choice</option>
<option>Women</option>
<option>Man</option>
</select>
I have tried this but without success:
<select class="form-control" name="sexe">
<option value="male" #if (old('sexe') == 'male') selected="selected" #endif>male</option>
<option value="female" #if (old('sexe') == 'female') selected="selected" #endif>female</option>
</select>
My Controller
public function edit($id)
{
//
$candidats = Candidat::find($id);
$permis = Permis::all();
return view('admin.candidats.edit', compact('candidats', 'permis'));
}
public function update(Request $request, $id)
{
$request->validate([
'sexe' => 'required|string',
'fk_permis' => 'required'
]);
$candidats = Candidat::find($id);
$candidats->sexe = $request->get('sexe');
$candidats->fk_permis = $request->get('fk_permis');
$candidats->save();
return redirect()->route('candidats.index')
->with('success', 'mise à jour effectuée');
}
Edit:
1) index.blade.php
2) edit.blade.php
In your update function put withInput():
return redirect()->route('candidats.index')
->with('success', 'mise à jour effectuée')->withInput();
In your select you can do this:
<select class="form-control" name="sexe">
<option value="male" #if (old('sexe') == 'male') selected="selected" #elseif($candidats->sexe == 'male') selected="selected"
#endif>male</option>
<option value="female" #if (old('sexe') == 'female') selected="selected" #elseif($candidats->sexe == 'female') selected="selected"
#endif>female</option>
</select>
I loaded the selected option from your model here
#elseif($candidats->sexe == 'male') selected="selected"
So, if you saved 'male' in your sexe attribute this option will be selected.
Take a look here for more info:
If the old data was stored as a model, which I assume it was since this is a Laravel question and not a javascript question, you can use form-model binding to easily load the old data the next time you go to the page.
So, when you open your form, bind the model:
{{ Form::model($yourModel, array('route' => array('yourModel.update', $yourModel->id))) }}
And then within the select method, laravel (collective) can automatically make the old data the selected value. Using the Laravel helper it might look like this:
{!! Form::select('sexe', $listOfYourNameAndIdForYourSelectItem, null, ['class'=>'form-control', 'id'=>'sexe']) !!}
By making the third argument null, as above, Laravel will make the model's old data the selected element.
Check the docs on the Laravel forms package for more info.
I have a drop downselect for several subjects in my Prestashop contact form.
<select id="id_contact" name="id_contact" class="form-control" onchange="showElemFromSelect('id_contact', 'desc_contact')">
<option value="0">-- Please chose --</option>
<option value="1">Cancel order</option>
<option value="3">Check order</option>
<option value="2">Return a product</option>
</select>
Is there any possibility to create or to have the value of the subject chosen in the confirmation email received?:
If you added this subjects as contacts names in backoffice, then in controllers/front/ContactController method postProcess() find block:
$var_list = array(
'{order_name}' => '-',
'{attached_file}' => '-',
'{message}' => Tools::nl2br(stripslashes($message)),
'{email}' => $from,
'{product_name}' => '',
);
and add $contact->name e.g. to {message}
'{message}' => '<br />Subject: '. $contact->name . '<br />' .Tools::nl2br(stripslashes($message)),
I have a code like this on my form.phtml, its a custom multiple select.
<select name="projecttype[]" multiple="multiple">
<option value="" selected>Select...</option>
<option value="Kitchen remodeling">Kitchen</option>
<option value="Refacing">Reface</option>
<option value="Counter tops">Counters</option>
<option value="Bathroom remodeling">Bathrooms</option>
<option value="Flooring">Floors</option>
<option value="Lighting">Lights</option>
<option value="Other">Others</option>
</select>
Now my problem is, how could I get those values if lets say I select "Floors and Lights" in my contact form. Because in normal select option, I could have a Project Type: {{var data.projecttype}} in custom form Email Template. But this one is a multiple select. This is my first time to encounter a problem like this but I can't find a good source as my guide on internet that something a good guide for this. Hope someone could help and guide me with this.
If you need to get value of multiselect box, you can use jQuery for that. See the below sample code.
<select id="multipleSelect" name="projecttype[]" multiple="multiple">
<option value="" selected>Select...</option>
<option value="Kitchen remodeling">Kitchen</option>
<option value="Refacing">Reface</option>
<option value="Counter tops">Counters</option>
<option value="Bathroom remodeling">Bathrooms</option>
<option value="Flooring">Floors</option>
<option value="Lighting">Lights</option>
<option value="Other">Others</option>
</select>
<div onclick="javascript:getValues();">TEST ME</div>
<script type="text/javascript">
function getValues(){
var selectedValues = jQuery('#multipleSelect').val();
alert(selectedValues);//alert if you want to
}
</script>
When you click on TEST ME <div>, you can see the values selected.
The above is a demo code. You can change it as per your needs.
Did you tried in this way...
foreach ($_GET['projecttype'] as $selectedOption)
echo $selectedOption."\n";
I came up to my mind to create a new phtml, and i just make my own mail and add this code
<?php
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$hear = $_POST['hear'];
$projecttype = implode(', ', $_POST['projecttype']);
$comment = $_POST['comment'];
$to = 'webdev2all#gmail.com';
$subject = 'Contact Form';
$message = 'Name: ' . $name . "\r\n" .
'E-mail: ' . $email . "\r\n" .
'Telephone: ' . $telephone . "\r\n" .
'How did you hear about us: ' . $hear . "\r\n" .
'Project Type: ' . $projecttype . "\r\n\r\n" .
'Comment: ' . $comment;
$headers = 'From: '. $name .' '. $email . "\r\n" .
'Reply-To: webdev2all#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
?>
I also change my form action to
action="<?php echo $actual_link; ?>"
now my contact page form is working as I needed...
thanks for the replies...