I want to give users the ability to sort posts themselves using some filter links on the side, so for instance:
To sort by title: www.example.com/?orderby=title&order=asc
To sort by date: www.example.com/?orderby=date&order=asc
So I want to be able to sort posts using a custom field called "shares" that returns a number , and I use Advanced Custom Fields plugin to generate that field, but not sure how I can generate such query and more importantly, giving a link to apply it if possible.
thanks in advance.
Try this simple code and after making sure that it works, you need to improve it yourself (adding conditions f.e.)
add_action('pre_get_posts','order_post_filter');
function order_post_filter($query){
//then you will need to add some condition here
if (isset($_GET["orderby"]) and isset($_GET["order"])){
$order=$_GET["order"]=='DESC'?'DESC':'ASC';
$query->set('order',$order);
if ($_GET["orderby"]=='date'){
$orderby='date';
}
elseif ($_GET["orderby"]=='title'){
$orderby='title';
}
else {
$query->set('meta_key',$_GET["orderby"]);
$orderby='meta_value';
}
$query->set('orderby',$orderby);
}
}
Related
I want to use the category id of the place described here: https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics-places/places-category-system-full.html.
How can i get it? Via the searchEngine?
I tried:
if !places.isEmpty {
for place in places {
let placeIdQuery = PlaceIdQuery(place.id)
searchEngine.search(placeIdQuery: placeIdQuery, languageCode: .deDe, completion: onFollowUpSearchCompleted)
}
}
But i only get the same places.
Found it.
Every Place has the optional details -> category.
I always look for questions to see if someone has had it, but I can't find an answer after a long time.
I renamed some wooocommerce chekout fields with the function:
function custom_rename_wc_checkout_fields ($ fields) {
For example I have renamed the placeholder and label "billing_last _name" as NIF/CIF with the function:
function custom_rename_wc_checkout_fields ($ fields) {
$ fields ['billing'] ['billing_last_name'] ['placeholder'] = 'NIF/CIF';
$ fields ['billing'] ['billing_last_name'] ['label'] = 'NIF/CIF';
return $ fields;
}
But I need to change the text also in admin single order so that when you have to create a new order from admin, the admintrator (or other role) knows the title of each field.
In the checkout page in "Billing first name" field, the customer will see NIF / CIF but when the administrator sees the field from the admin single order or he want create an order it will still appear as "Firt Name"
Does anyone know how I can change the texts?
Thanks for your help.
you can change this text with the filter woocommerce_admin_billing_fields
https://docs.woocommerce.com/wc-apidocs/source-class-WC_Meta_Box_Order_Data.html#40-90
I use event listener for change data dynamically based on user inputs. Each time I use PRE_SET_DATA and PRE_SUBMIT events for set data and fields choices. Here is the simple example of actions from PRE_SUBMIT:
// Pre set share locations by share day
if (array_key_exists('shares', $data)) {
foreach ($data['shares'] as $key => $share) {
if ($share['pickUpDay'] !== null) {
$shareType = $form->get('shares')->get($key);
$locations = $this->em->getRepository('AppBundle:Member\Location')->getLocationsByDay($client, $data['shares'][$key]['pickUpDay']);
$this->addLocationField($shareType, $locations);
}
}
}
Not matter what inside addLocationField function, it works right.
When I do $form->get('shares'), its my collection field, then I need to ->get(child) of this collection and set fields data and choices straight to this child. By when I add collection dynamically, Symfony shows error:
Child "n" does not exist.
And this problem happens only when I try to get data of new collection that was added dynamically. So I can't get to a collection field and change choices, so I receive error that my new value is not in a choice list.
Interesting that $data['shares'] have all data for new collection elements, but $form->get('shares') haven`t:
var_dump(count($event->getData()['shares'])) - return 1;
var_dump(count($form->get('shares'))) - return 0;
Is that mean that my PRE_SUBMIT works before Symfony collection functionality happen?
Someone know how to fix it?
I know your question is "old" and you probably found a solution but you were in the right direction when you said :
Is that mean that my PRE_SUBMIT works before Symfony collection functionality happen?
Your new collection is not submitted yet and it is not present in the model see this part of the doc
To make what you want to, you should use the SUBMIT event
NB : You can't add any field on POST_SUBMIT
I'd like to disable all POSTs to an OpenACS/AOLServer installation. Is there an good singular place – a request-hook or wrapper/middleware – to do this?
(Bonus points if the intercept can let a few URI patterns or logged-in users through.)
Yes, this is straight forward to do. You have a choice here: you can register a proc to run instead of all POSTs, or can you register a filter to run before the POST and filter out certain users or whatever. I think the filter is a better choice.
To do this you register your proc or filter using ns_register_proc or ns_register_filter (with preauth). Put the following code in a .tcl file under the tcl folder of an OpenACS package or under the main AOLserver /web/servername/tcl directory.
Filter example:
ns_register_filter preauth POST / filter_posts
proc filter_posts {} {
set user_id [ad_verify_and_get_user_id]
set list_of_allowed_user_ids [21 567 8999]
if {[lsearch -exact $list_of_allowed_user_ids $user_id] == -1 } {
#this user isn't allowed - so redirect them
ns_returnredirect "/register/"
# tell AOLserver to abort this thread
return filter_return
} else {
# this user is allowed, tell AOLserver to continue
return filter_ok
}
}
Proc example:
ns_register_proc POST / handle_posts
proc handle_posts {} {
ns_returnredirect "http://someotherwebsite.com"
}
if([node:term] == "Main Stage Theatre"){return TRUE;}
First I have a condition that checks the node creation of an Event.
Now, this second condition i want to check the taxonomy terms, and if it is the right one it will add to the my node queue.
my above piece of code I don't think is correct. Can someone help me with the check a truth value feature?
Your code looks correct, did you include PHP tags? You have to wrap your code in <?php ?> tags in the Truth value textfield.
I have this working with:
<?php if ('[node:term]' == 'Comedy') { return TRUE; } else { return FALSE; } ?>
Note: If you are allowing multiple terms to be selected for an Event node, [node:term] only returns the "top" term.
For that kind of comparison I suggest using "text comparison"; it compares two text fields and evaluates TRUE if the two fields match. You could use a "token" (e.g. [node:term] in your example) in one field and text (e.g. Main Stage Theatre) in the other field. You can also check a box to return true if the two fields do not evaluate as equal and there is another checkbox option to use Regex for the match comparison. I just used it to check the language of the content a comment was left on.