if I understand you correctly, you might want something like this:
global $wpdb;
$number=30; // EDIT this to your needs
$sql="SELECT post_id
FROM `wp_ak_popularity`
ORDER BY `single_views`
DESC LIMIT %d";
$my_top_posts = $wpdb->get_results($wpdb->prepare($sql,$number),ARRAY_N);
to get an array of the top posts id’s.
You could then use this in your WP_Query:
'post__in' => $my_top_posts
Related Posts:
- Undefined function mysql_connect()
- Can i use php sql functions instead of $wpdb?
- How to validate WordPress generated password in DB using PHP?
- How to get the list of WooCommerce product image of a certain category from database?
- Custom query to get post names beginning with a digit
- How To Make Connection To WordPress Data Base In A Plugin?
- Changing user_nicename
- WordPress will not operate correctly
- tag search using WP_Query
- 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
- Your PHP installation appears to be missing the MySQL extension which is required by WordPress
- How to track a users progress through pages by inserting data into WordPress Database?
- the_author_meta not working
- if statement on database query
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Sortable admin column for one meta key with three possible meta values
- WordPress Ajax Custom Query – High CPU LOAD
- AJAX in WordPress, sending coords data to MySQL and show after into map
- 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
- Styling images coming from another blog
- mysqli_real_connect() – authentication method unknown to the client Warnings
- 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 convert objects into arrays
- Ajax $wpdb not returning table data
- Is there a way to get 3+ dimensional array from a single MySql command
- Remove one value in dismissed_wp_pointers?
- Can’t get wp_insert_post to work
- Accessing data from a non-WP database/table within a page content
- I want to select the from values from database in WordPress? [closed]
- mysql query from wordpress page using custom table
- User management system similar to wordpress one?
- Importing Geo data into wordpress database
- PHP Fatal error: Uncaught mysqli_sql_exception: Table doesn’t exist in wordpress/wp-includes/wp-db.php
- SQL Injection blocked by firewall
- How to check if a meta value has already been assigned to any user?
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Ordering users by custom user meta
- Long running queries
- Not connecting to database in file with multiple MySQL connections
- Way to bulk make all my tags lowercase?
- $Wpdb post meta query is not working with mutliple meta keys and values? [closed]
- Multiple meta_key in one global $wpdb;
- Custom array from a query only write the last row of the query
- WordPress member notification
- WordPress Block developer from exporting Database via PHP
- php include not working in custom page
- How do I display offsite database info on my wordpress site?
- 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
- WordPress WP_Query without query GET parameters
- 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
- Query the links Database
- Most viewed posts in WordPress
- SQL error with custom query
- Modify WooCommerce used to get all orders in dashboard
- What’s wrong in my PHP code? I’m using WordPress Astra Theme and I can’t insert data into my SQL
- Get mysql data for Quick Edit panel
- Weird fonts showing which are coming from database
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- 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
- 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?
- Change upload URL by mime type
- autocomplete in wordpress using ajax with json-data
- Unexpected behavior when trying to manually install WordPress on macOS Sierra
- WordPress post insertion from PHP file
- 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
- Rewrite SQL query as a prepared statement and use in foreach loop
- SQL Query Search page
- Include a custom field in mysql query
- Insert double entry in DB
- Splitting One Big WordPress Site into Multiple Small Sites
- How to pass username into form that sends data to database
- How to edit the default database of WordPress [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