Order by title without taking into account 'the' in Wordpress (wp_query) - sql-order-by

I currently have episodes from a TV Show that feature bands playing, so for example I have:
Moby
The Dandy Warhols
The Kooks
My wp_query looks like this:
$loop = new WP_Query(array('post_type' => 'episodio', 'cat' => '9', 'posts_per_page' => 90, 'orderby' => 'title','order' => 'ASC' ));
But I want to order them like this, alphabetically, without taking into account 'the':
The Dandy Warhols
The Kooks
Moby
There are a lot of records in the database, so it's not very practical and/or efficient to get everything into an array, remove 'the', order again and then going through the array to display the data.
Is this possible in WP? Maybe through a filter?
Thanks a lot in advance! :)

$loop = new WP_Query(array('post_type' => 'episodio', 'cat' => '9', 'posts_per_page' => 90, 'orderby' => 'title','order' => 'DESC' ));
you will get result post title descending of category 9.

Related

How with laravel/pint to make keys and values are aligned with spaces on the same level?

In Laravel 9 app using laravel/pint (1.4) with "psr12" preset I prefer to see not code :
\DB::table('quizzes')->insert([
'id' => 2,
'question' => 'What does ORM stand for?',
'quiz_category_id' => 1,
'points' => 4,
'active' => true,
]);
But:
\DB::table('quizzes')->insert([
'id' => 2,
'question' => 'What does ORM stand for?',
'quiz_category_id' => 1,
'points' => 4,
'active' => true,
]);
where keys and values are aligned with spaces on the same level.
I tried to fix it and found property “binary_operator_spaces”
But looking at docs :
https://github.com/laravel/pint/blob/main/resources/presets/laravel.php
I see only 1 rule :
'binary_operator_spaces' => [
'default' => 'single_space',
],
Not sure, but how can I set this rule? Seems it does not hae any other rules...
Thanks!
Check the documentation for binary_operator_spaces
You want to use that rule with the align_single_space_minimal option:
'binary_operator_spaces' => [
'default' => 'align_single_space_minimal',
],
That is if you have the same setup as shown in the link you provided
If you were using PHPCodeSniffer (which is what laravel is using behind the scenes) you would simply use it this way:
$config->setRuleset([
'Squiz.WhiteSpace.OperatorSpacing' => [
'align_single_space_minimal' => true
]
]);
Just remember that each space is 1 byte, and those add up... a pedantic-thought but one to keep in your head none-the-less (imho no one should use this rule or add pointless whitespace to array)

Laravel validation in combination of two array data

How could I validate it from request file?
I want to check distinct combining floor_id and material_id,
having a floor id can not have same material_id twice or more
From a form data i get this kind of output
project_id => 5,
date => 12-15-2022,
floor_id => array(
0=> 1,
1=> 5,
2=> 12
),
material_id => array(
0=>15,
1=>2,
2=>20
),
quantity => array(
0=>2500,
1=>3500,
2=>6522
)
How could I validate it from request file
may be you can use validation distinct
https://laravel.com/docs/9.x/validation#rule-distinct
You can write a custom validation rule to serve your purpose.
Here you will get some idea https://laravel.com/docs/9.x/validation#custom-validation-rules

Magento both AND and OR conditions in a collection

I want make a query which looks like below to filter some products (using attributes) from product collection.
SELECT <attributes>
FROM <tables & joins>
WHERE (<some AND conditions>) OR (<some AND conditions>)
WHERE condition should filter products that match either first set of AND conditions or second set of AND conditions.
Problem is I can't find a way to add an OR condition in between multiple AND conditions.
Can anyone help me to code above where condition using Magento addAttributeToFilter()? or any other functions?
If i'm understanding you correctly I think you need to do some variation of this:
->addAttributeToFilter(...filter here...)
->addAttributeToFilter(array(
array(
'attribute' => 'special_to_date',
'date' => true,
'from' => $dateTomorrow
),
array(
'attribute' => 'special_to_date',
'null' => 1
)
));
which would be:
...filter here... AND (special_to_date >= '2012-07-03' OR special_to_date IS NULL)...

how to update Cart Options in Codeigniter?

Through Documents provided by Codeigniter Its Cart Library doesnt Update its options We can add the Options like that
$data = array(
array(
'id' => 'sku_123ABC',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'L', 'Color' => 'Red')
)
);
$this->cart->insert($data);
Is there any other way or any tutorial to learn how we can update options of Cart just like
$qid = $this->input->post("qid");
$pairs = $this->input->post("pairs");
$males = $this->input->post("males");
$females = $this->input->post("females");
$data = array(
array(
'rowid' => $qid,
'qty' => 1,
'options' => array('pairs' => $pairs, 'males' => $males, 'females' => $females))
);
$this->cart->update($data);
I have searched it but seems no one has made any fix for it?
Though I have not found any solution therefore I am using simple solution and that is just rest the item in cart and adding new item with same id and updated option values. Its not great trick though but it is just working for me.
I am fallen yesterday like this kind of problem then i create Extending / Override update function. Here how to Extending Native library Link : Create CI Library
Here is my modified code in Github Link
I hope it will help someone and also can modify as their need.
No it did not work for me.. but there is no any errors, I check the array within the _update function as well,
Array
(
[id] => 177
[rowid] => 66bd8895e10f189f62bf3a65ada83630
[qty] => 1
[options] => Array
(
[vat] => 0
[discount] => 0
)
)
I know i'ts just too late but I want to share my solution:
I just got the the options in an array and updated it as I wanted and then update the entire options field in the cart with the array content.
Hope this help somebody.
Sorry for the english.
The way I tried was a bit difficult but it works. You can’t just update a single option value. To update you have to pass all the existing values to all the option values with the value you want to update as well.
If you want to update your Size option
$data = array(
‘rowid’ => $yourRowIdHere,
‘options’ => array ( ‘color’ => $yourExistingValue, ‘length’ => $yourExistingValue, ‘size’ => $newUpdatedValue)
));
$this->cart->update($data);
Give it a try :)

Multiple level ordering in Yii

This is my CActiveDataProvider
$dataProvider = new CActiveDataProvider ('MyTable', array (
'pagination' => array (
'PageSize' => 4,
),
'criteria' => array (
'condition' => 'from_user_id='.$user->id,
'order' => 'date DESC',
),
));
My question is: I would like to have this CActiveDataProvider ordered first by date (as the posted code does), and in a second level, within those with the same date, order by a second criteria. Is this possible?
Maybe I'm not understanding you correctly, but won't the following work? :
'order' => 'date DESC, name DESC',

Resources