Assuming that you want to get posts with that meta key, regardless of content, and order by that meta value, you would need to set two properties.
- meta_query
- orderby
So the code, based of your question would be like this
// Custom query to order 'recommended reading' posts by populatrity
add_action('elementor/query/my_custom_filter', function ($query) {
if (empty($meta_query = $query->get('meta_query'))) $meta_query = [];
// add our condition to the meta_query
$meta_query['google_unique_page_views'] = [
'key' => 'google_unique_page_views',
'compare' => 'EXISTS',
];
// set the new meta_query
$query->set('meta_query', $meta_query);
// set the new orderby
$query->set('orderby', [
'google_unique_page_views' => 'DESC' // or ASC, based on your needs
]);
});
Related Posts:
- Use REGEXP in WP_Query meta_query key
- WP_Query with different postmeta filter for each categories
- Slow WP_Query with ‘OR’ on meta_query
- meta_query weird behaviour, static int will work, but not user data
- query post based on comparison
- WP_Query filtering in ACF field containing dates
- Meta_query compare operator explanation
- meta_query with meta values as serialize arrays
- Nested meta_query with multiple relation keys
- meta_query ‘compare’ => ‘IN’ not working
- WP Query Args – Title or Meta Value
- Meta query with string starting like pattern
- compare meta_query in get_posts arguments
- How to query posts based on lat-lng coordinate as post meta?
- how to show posts that are missing a meta_value
- Set Alias for meta_query arguments in get_posts()
- Sorting: custom query with orderby meta_value_num THEN by title
- Display products from specific category in shop page
- How to list some posts first in the loop based on post id
- Whats the difference between post_limits and pre_get_posts?
- How to add taxonomy filter on the query fly?
- How to Compare Two Meta Fields
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Does tax_query really beats meta_query in all situations?
- WP_Query – filter or directly?
- WP_Query with checkbox meta_query
- ACF Relationship Field Search Filtering [closed]
- What is the most efficient way of querying posts based on visits and date for current day?
- Add indexing to meta_value in wp_postmeta
- Is it possible to orderby multiple meta_keys when using meta_value_num?
- Custom WP_Query order by post_meta and (author) user_meta
- Query WooCommerce orders where meta data does not exist
- Getting attachments by meta value
- Query Multiple Post types each with own meta query
- Changing Posts Per Page and offset with pre_get_posts
- Execute a large WP_Query with many “AND” Meta_Queries?
- ajax category filter
- Query all posts where meta value is empty
- How to order posts tag by tag?
- Overriding The Loop with filter or hook
- WP_Query min and max values
- Custom query incorrectly returning everything [closed]
- WP Rest API v2 return posts with specific tag
- ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format
- WP_Query using meta_query with relation OR and orderby meta_value doesn’t work
- Using custom meta_query with relation not working as expected
- How to filter sql only for a specific post type
- Perform query with meta_value date
- querying with custom meta field with meta_query
- Order by two meta keys
- multiple meta key but get server load is very high
- Meta Query with date and time on the same Day before given time
- A WP_Query that will look for posts after 2 weeks ago OR with a certain meta value
- Ignore a filter on the media library
- How to grab metabox value in wp_query meta_query key
- WP_Query meta_query where meta value ends in space
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- How to support multiple search terms query within one process?
- Nested query inside Logical operator OR not working in meta_query
- Is “orderby” in WP Meta Query conflicting with Meta Query?
- Query by meta_key and order by meta_value_num return orderby date
- What is an efficient way to query based on post_meta?
- WP_Query not working as expected for attachments and custom meta_query
- datetime picker, timestamps and meta queries
- How do I create my own nested meta_query using posts_where / posts_join?
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- How to order a post type with meta_value_num and if meta_value_num does not exist then order by date
- Compare two meta-fields in a wp_query (where meta-field-A is larger than meta-field-B)
- Wp_query order by multiple custom fields?
- How can I create a WP_Query that returns posts where one meta_value
- How to get any tag ID
- Meta Query querrying several post types based on ACF fields is broken after update to WP 4.1
- WordPress altering my custom query, How to fix it?
- WP Meta Query for some meta (array) values
- Exclude post on loop by multiple meta key value
- Sort users by meta_value_num
- Querying by taxonomy vs Querying by Custom fields Speed Comparison
- meta_query with array as value
- How to get sum of meta_values of a meta_key in wp_query according to conditions
- How to query ‘posts_per_page’ to display a different blog posts index template?
- Order by meta_key in custom post type doesn’t affect the query
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- How to create/modfiy WP_Query to search in post title OR custom field?
- Using WP Query to search within ALL keys in meta query
- Order By Multiple Meta Fields
- Which filter/action hook gets triggered after a query has been performed?
- WP Query – Get WooCommerce Products with variation that is in stock
- Meta_query with or without value
- meta_key and meta_value not working together
- Use meta_query to display events by date in custom field
- Advanced WP Query hogs the SQL server
- Remove ellipsis from the excerpt retrieved using get_the_excerpt()
- Order posts by meta value and Date
- Query sticky posts with thumbnails
- Removing posts from the returned wp_query. Cannot use object of type WP_Query as array
- Order WP Query posts by custom order calculated from post meta values
- Meta-value query
- How to get user_id from wordpress database inside ajax function?
- how to speed up a complex wp_query?