There is no examples or documentation for doing that.
Your need is pretty custom so you’re probably going to have to hook into the query, via filter, to set this up. I would recommend the ‘posts_clauses’ filter because it gives you access to all the query clauses in one filter.
The ‘posts_clauses’ passes two parameters: the clauses (separated into an array) and the actual query. So your filter would start out like this:
add_filter( 'posts_clauses', 'my_website_posts_clauses_filter', 1, 2 );
function my_website_posts_clauses_filter( $clauses, &$this ) {
return $clauses;
}
The different clauses are: ‘where’, ‘groupby’, ‘join’, ‘orderby’, ‘distinct’, ‘fields’ and ‘limits’.
You’re going to have to filter the ‘fields’ to make sure your two custom fields are being queried and then you can filter the ‘where’ to add in your discount logic.
But make you sure remember this is a filter so you don’t want to overwrite what already exists, you’re just adding on to it.
Hope this points you in the right direction.
Thanks for advice, but I think is too hard for me.
I hope someone who can do it to help me 🙂
I still wait responses.
Stop bumping
I think “posts_orderby” may help me, but I dont know how to use it.
Someone can help me?