I think you’re close with your 2nd snippet, but you should be using meta_value_num
instead of meta_key_num
.
$query->set( 'meta_key', 'comment_karma' );
$query->set( 'orderby', 'meta_value_num' );
See the WP_Query orderby
docs for more info.
Related Posts:
- How to list commenters and days since last commented
- the_date() not working
- Query multiple custom post types in single loop
- How to search display_name column when using WP_User_Query
- Using WP_Query – how to display something IF there are no results
- Getting the comment number relative to all the post’s comments
- How to order posts by modified date without using ‘query_posts’?
- Delete post revisions on post publish
- How to sort results from a custom database table
- Specific Loop For 2 Within Each
- How do I create comment-reply-button using element not
- How to check if comments are paginated?
- WP database error for comments_popup_link()
- How to add a post or page tag to the list of classes appearing in the body tag’s class attribute?
- Use two WP Query in template
- Add “last” and “first” to WordPress Comment Pagination Links
- Uncaught TypeError: Cannot read property ‘firstChild’ of null after upgrading to WordPress 5.5
- Automatically generate Post/Page from searched Database item?
- List User order by ID in Descending order (Backend)
- spliting posts into two columns
- WordPress – query 5 posts with a specific post in top
- How do I fetch all comments per post via WP REST API?
- How to get a list of all possible values of a specific user meta key?
- Show comments menu in dashboard only if the site has comment
- Custom filter in admin edit custom post type responding with invalid post type?
- Accessing the database from a plugin outside of action hooks
- Echo a hierarchical list of post data from custom fields
- Create WP_Query to search for posts by their categories or their parent/child categories
- Storing Array from returned database query and using the array in a new query
- What query string parameter is available for index.php, that works for both pages and blog articles?
- Sending data from custom inputs in WordPress comment form in the admin notification email
- ACF: how do I get the fields and its values of a specific group?
- Show wp_die if url form comment not emply
- Customize Theme comment template to Insert VoteUp and VoteDown buttons
- Set WP_query ‘order’ option by another tables value
- WordPress default Search function inconsistent in WooCommerce Product Titles
- wpdb php get_var query to get ID for URL image doesn’t work for ID over 999
- Two queries for a WP_User_Query search work perfectly apart, but not together
- edit_comment_link is not showing for comment author
- Limit 1 global comment per minute
- Query if audio attachment AND/OR custom field
- Genesis framework comments broken?
- WordPress SQL injection
- Which is the correct way to conditionally enqueue a CSS file?
- unable to use ‘new WP_Query’ in AJAX call
- Parse error: syntax error, unexpected ‘}’ on get_the_author_meta [closed]
- How to add text to the start of all comments?
- Does anyone know all parameters of get_comments()
- How to overwrite orderby with add_query_var
- Can’t update multiple rows with $wpdb query
- Appended comments but they show up above the content instead of below
- wp_delete_comment takes two tries to delete – then deletes all comments
- Change “No Comments” link to “My String” on Blog Post (Find Snippet in Code or use CSS, PHP Solution) [closed]
- Can I make get_users() query global?
- How to display SQL query that ran in WC_Order_Query?
- Custom Post type slider with thumbnail navigation
- How to hide posts of a specific custom category in WordPress?
- WordPress PHP syntax doesn’t seem to be working correctly
- Restrict characters in comment section
- Limit tags shown in post
- Why my query does not run with prepare
- List of Events with Multiple Dates: Only NEXT Date
- I don’t have comments.php… how do I customize my comment fields
- WordPress Custom Query: Combining Two Functions
- Reject all malicious URL requests functions.php
- WordPress Custom Form – Getting Query Vars, Weird Glitch?
- Add custom field on admin dashboard comments / reviews
- Display articles with a different template in the home page | Solved |
- array wordpress when get is null
- Reading URL Parameters
- How to pass parameters in wordpress shortcode?
- Display the list of user’s comments + the post title + date
- Category Page Displaying all Pages
- Why does a header location on admin_head remove the query var I’m setting in the location?
- getting the values of hidden inputs to use them in a php mysql query
- Offset with ajax load more posts duplicates
- How to add delete, approve, spam Links to Comments
- Real time notification on user profile after new comment
- How to do a MySql query in WordPress?
- What’s the correct offset value for order ASC?
- Echo multiple tasks if a common function exists
- How to enqueue assets only on queried pages, excluding the page being queried?
- A Space being added to url generated by custom plugin
- “Where… like” query not working as expected
- Problems With Query and/or Template Part and/or PHP
- Arrange Category post manually when displayed
- Get first comment link on the post itself
- How to callback custom field text
- Does wp_query and query_posts affect website performance? [duplicate]
- How to get the rating value of each comment
- Trouble figuring out how to get my button to submit comment
- How to insert a variable into a query parameter?
- How to convert my comment.html to comment.php
- wp_query on search results page showing all results every time
- WP_Query not returning results
- Sorting a custom post type in pre_get_posts
- Guests comment form – prevent duplicate email addresses
- SQL query to retrieve the number of WordPress posts with all given categories
- Permissions error when I use my plugin to delete comments in the front-end
- Custom Filtering date with newsletter