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
- compare meta_query in get_posts arguments
- Display products from specific category in shop page
- How to Compare Two Meta Fields
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Changing Posts Per Page and offset with pre_get_posts
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- Query by meta_key and order by meta_value_num return orderby date
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- Wp_query order by multiple custom fields?
- WordPress altering my custom query, How to fix it?
- 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 create/modfiy WP_Query to search in post title OR custom field?
- Remove ellipsis from the excerpt retrieved using get_the_excerpt()
- Multiple meta queries but arrange by specific meta value order
- Order Posts by meta value AND published date
- WP_Query with multiple meta fields filter?
- Use ‘parse_query’ filter to show posts that from multiple criteria
- Using apply_filters(‘the_content’, $custom_query->post_content) alters output
- Modifying the Search Results
- What format does the meta_query TIME type require?
- pre_get_posts order by not working
- WP_Query filter and order by meta ordering by wrong joined table
- WP_Query last five posts, simply ordered by meta_value
- Meta Query Array Error 500
- What is the random string I am seeing when I use get_query_var?
- Order by title without taking into account ‘the’
- Fetch Record based on meta key dates
- meta_query in WP_Query value is not accepting array
- Changing sort order for presentation by Jetpack infinite scroll
- meta_query not working as expected
- get posts by meta_key from inside key of post meta
- Help optimizing slow WP_Query with meta_query
- meta_value_num not ordering all items
- Meta Queries – should nesting work after WP 4.1?
- Filter and Order by Multiple Custom Meta Values
- Meta Query relation “AND” then set array accordingly
- 2 weeks ago from meta query meta value
- Query posts with “non set” meta value
- Query with meta_query and tax_query together not working properly
- Array as ‘key’ in WP_Query
- Ordering a mysql style datetime stamp with meta_query
- Is it possible to query a custom field where the value is between two fields?
- Include posts from some categories while excluding from others
- Filter posts by comparing custom meta value against postdate
- Searching for meta_key returns 0 posts
- Event with multiple dates, display events chronologically
- meta_query fails to compare on values containing apostrophes
- Change AJAX filter from POST to GET for URL Parameters
- Check if searched number is within the post meta value
- Filtering posts by archive showing all years
- WP_Query – How to get all posts of specific days of week by custom field date?
- Multiple wp_query on archive page
- add_query_arg to compare and display events from a certain date
- Custom post type – filter content by custom meta box content
- WP_Query not returning correct result with meta_query parameter
- Query on meta values and post title
- Combine query in WP_User_Query()
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- How can I modify the query by adding to the existing query?
- Meta query ignores multiple values of the key
- WordPress Query custom ordering by temporary variable
- Comparing Meta Field date in WPQuery using Meta_Query?
- Get unique post by meta value using wp_query
- How to create better WP_Query to look for date time which is anywhere between two meta values?
- WP_Query, ACF field and array
- Filtering WP_Query based on wp_postmeta keys values
- Complex Meta Query
- WP Query filters active on wrong query
- Multiple meta_query not working
- Insert wp_query after the_content with plugin (filter the_content won’t work)
- compare for multiple meta values for same key in wp_query
- Gather same custom field values in one value in a select tag with wp_query
- datetime picker, timestamps and meta queries
- WP_Query with meta_query won’t orderby
- meta_query only check if both value are set
- Get posts meta_query by repater field
- Query 3 meta_key and orderby
- wp_query sorting – one specific meta_key value at last and then sort by create date
- Fetch only categorized posts
- Extending WP Query: Custom geolocation meta values work, but tax_query breaks
- Using custom field as ‘orderby’ value causing post grouping by publish date
- Get closest event where meta_key field is an array
- Set right order for query that returns posts based on two custom fields
- Meta_query weird behaviour
- Looking for a way to exclude frontpage and nav menu from query filter
- Creating Custom Query
- Get posts by meta value except one post [closed]
- WP_Query by meta key not returning any posts
- Using ‘meta_query’ with the ‘pre_get_posts()’ hook disables searching for post titles
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Get posts using multiple values from ACF checkbox as meta query wordpress
- get_post_meta bringing back results, but $wpdb->postmeta doesn’t
- Custom query with custom filtering returning incorrect results
- WP Query returning all posts when Meta_query is null