I created a search filter that displays posts randomly, and I wonder how can I always display a specific post item in the first position of the search results and display the rest of the items normally.
Thank you for your help @dassoun, here is the query :
$taxonomies = array('recipe_type', 'product_category', 'recipe_category', 'recipe_event', 'recipe_diet');
foreach ($taxonomies as $taxonomy) {
$taxonomies_taxonomy[$taxonomy] = get_taxonomy($taxonomy);
$taxonomies_terms[$taxonomy] = get_terms(
array(
'taxonomy' => $taxonomy,
'hide_empty' => false,
'meta_key' => 'filter_order',
'orderby' => 'meta_value_num',
'order' => 'ASC'
)
);
$taxonomies_selected[$taxonomy] = (get_query_var($taxonomy)) ? get_query_var($taxonomy) : '';
}
I think you should have a look at the "UNION" operator.
from https://www.w3schools.com/sql/sql_union.asp: The UNION operator is used to combine the result-set of two or more SELECT statements.
The idea would be:
select * from post where (hastobetop = 1 or id = myid or whatever)
UNION
yourfilteredrequest
You may have to exlude the rows returned by the first request from the filtered one.
[edit] Sorry, I hadn't seen it was specific to wordpress [/edit]