http://www.catswhocode.com/blog/super-useful-wordpress-hacks-and-snippets
You source? I made a widget that does just that, on this same code.
To sort:
<?php
$args = array(
'post_status' => 'publish',
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
$the_query = new WP_Query($args); //http://codex.wordpress.org/Class_Reference/WP_Query
//the loop
while ( $the_query->have_posts() ) : $the_query->the_post();
//do your magic
endwhile;
Related Posts:
- Undefined function mysql_connect()
- MySQL “Or” Condition
- Transaction when using WP functions rather than vanilla SQL?
- Can i use php sql functions instead of $wpdb?
- How to validate WordPress generated password in DB using PHP?
- Custom query to get post names beginning with a digit
- How To Make Connection To WordPress Data Base In A Plugin?
- Jquery ajax to custom php file: returning blank data
- Add value to usermeta without removing previous values?
- How can I call a row of user specific data from a custom table added to the WP Database
- How to merge local and live databases?
- How to track a users progress through pages by inserting data into WordPress Database?
- the_author_meta not working
- Successful or Error Message after running mysql code in functions.php
- Performance issues with large website [closed]
- Create a quick start wordpress installation [closed]
- How to migrate the posts from an old custom legacy blog to a new WordPress website?
- theme options echoing multiple times
- WordPress 3 – how are passwords stored and how do I compare to them?
- WordPress get pagination on wpdb get_results
- mysqli_real_connect() – authentication method unknown to the client Warnings
- How to create another version of my site based on the same database
- how to echo all tables that start with a prefix
- Do I need to prepare query before get_results(), get_row() and get_var()?
- How to create and work with custom data / tables (i.e., for arbitrary data)?
- How to select WooCommerce products by post_meta and order them
- Stumped on migration
- Is XAMPP faster than running LAMP in WSL on Windows 10? [closed]
- Remove one value in dismissed_wp_pointers?
- WordPress Site Running Extremely Slow on Dedicated Server
- Accessing data from a non-WP database/table within a page content
- Get updated query results on page after insert in database
- I want to select the from values from database in WordPress? [closed]
- User management system similar to wordpress one?
- SQL Injection blocked by firewall
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- How can I save unique user data on my site? [closed]
- Ordering users by custom user meta
- Long running queries
- How to split links generated into an xml sitemap to avoid exceeding 30 sec maximum execution time?
- Hacked WordPress website /Homepage redirect [closed]
- Refresh table data with Ajax
- Database query works fine outside WordPress
- Using custom tables for old posts
- How i can obtain all the post meta for a specific post as an array?
- Multiple meta_key in one global $wpdb;
- Custom array from a query only write the last row of the query
- WordPress member notification
- Moving wordpress site from localhost to live server using GoDaddy cPanel
- How does WP work in conjunction with a web server?
- WordPress Block developer from exporting Database via PHP
- Location of core code for database connection and get_header
- How do I display offsite database info on my wordpress site?
- Creating Database Table vs. Adding MetaData to Post & User
- WordPress and MySQL: trying to print data using PHP from user_meta custom field data
- Most commented posts by time period (last 12h, last 24h and etc)
- Use $wpdb or other PHP script method to find/replace in WP database
- Issue with fetching mysql data and displaying results via shortcode in webpage
- Hide posts if user is added to it WP_query
- Custom route and query
- How to unserialize data from MySQL
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- Known Issues in WordPress When Upgrading PHP to ver 7
- Edit Account – read and write to MySQL
- Get the id of the row from database on click of a button [closed]
- WPDB secure custom form
- Why when I create a new post I found 2 record related to this post into the posts database table?
- mySQL queries are executed twice on wordpress website
- SQL error with custom query
- MySQL Query Returns Array () In Shortcode
- Modify WooCommerce used to get all orders in dashboard
- Passing in MySQL prepare statement parameter separately throwing error
- Database SQL query error
- Display Results of SQL Query on WP site
- Weird fonts showing which are coming from database
- PHP Warning: mysqli_query(): after updating my websites php from 5.6 to 7.2
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- Updated Php version from 5.4 to 7.2 and getting “PHP installation missing the MySQL extension needed by WordPress”
- WordPress Bad Request Error 400
- I am facing this error Your PHP installation appears to be missing the MySQL extension which is required by WordPress
- How to display MySQL table data which is stored as an array?
- What is the correct way to search 3 custom fields only in WordPress?
- cant insert data in a custom table in phpmyadmin
- How to import woocommerce custom fields data into another site?
- autocomplete in wordpress using ajax with json-data
- Need help with format of nested array in MySQL
- New database entry to trigger runing PHP/SQL query through link with token, without logging into the website
- Query doesn’t display text data with apostrophes
- I want show only data for today
- SQL Query Search page
- MySQL queries in WordPress
- Splash pages on a high traffic site
- Let users register weight each day and save it in DB
- How to pass username into form that sends data to database
- Submit cf7 form to cfdb as pdf/BLOB [closed]
- Your PHP installation appears to be missing the MySQL … After deleting and restarting from cpanel
- How to set variable to specific field when querying
- How to get a database field value from a WordPress table? [closed]
- Error resetting database index using ALTER TABLE in $wpdb->query