Order queries by meta_value even if meta_key is not filled
-
Hello! I want to sort search results by the value of custom field (‘name-official’) for all posts (is this field filled or not).
But when I add filter in function.php likefunction searchExcludePages($query) { if ($query->is_search) { $query->set('orderby','meta_value'); $query->set('meta_key','name-official'); $query->set('order','ASC'); } return $query; } add_filter('pre_get_posts','searchExcludePages');
i’ve received results with filled ‘name-official’ only. What should i do to get results with non-filled field too?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Order queries by meta_value even if meta_key is not filled’ is closed to new replies.