Your query is incorrect in the first place because you’re not doing the join correctly. What you’re actually selecting with that query is just all the postmeta’s autor fields, without regards to whether the post is published or not.
Here’s the corrected query.
SELECT meta_value AS autor FROM wp_posts
JOIN wp_postmeta ON (wp_postmeta.post_id = wp_posts.ID)
WHERE post_status="publish"
AND meta_key = 'autor'
GROUP BY meta_value
ORDER BY meta_value
This will probably be faster because the proper join will eliminate a lot of the posts. It’s not fully optimal, but it will give some improvement.
Related Posts:
- XOR functionality for meta_query
- How can I change my meta_query to SQL wpdb query?
- wpdb->insert: do I need to prepare against SQL injection?
- How do I check for a duplicate record before inserting using wpdb
- How to use $wpdb to delete in a custom table
- WPDB prepare – like % – placeholders?
- $wpdb->update multiple rows, like IN in normal SQL
- Avoiding “Usage of a direct database call is discouraged”
- dbDelta does not create Table, but returns success
- Saving custom form data into database
- Search multiple meta keys at once
- passing variables as parameters to stored procedures via wpdb from php-script
- wp-content/db.php : where is this file?
- Quotes in table name
- $wpdb->get_results() returns good result only in first foreach iteration
- $wpdb->insert – inserting multiple rows
- WPDB->insert with special characters
- How Can I Use $wpdb in PayPal IPN file?
- Is there a (better) way to access $wpdb results?
- Set media metadata (i.e. “dimensions” field) on SVG file after extracting it with a filter
- $wpdb->prepare not working with update table prefix
- How to use prepare to query with variables
- Use $wpdb in wordpress theme files
- $wpdb not returning data
- WPDB update row with != in where clause
- wpdb->get_row() / get_results – is it possible to return an object instances of my own class?
- Problem in creating table through plugin code
- How to email user after inserting the username in database in WordPress
- $wpdb->replace / Replace or update primary key
- How to fetch an array in $wpdb?
- $wpdb – do you have to use foreach even if there will always only be one result?
- Need help writing a $wpdb query
- $wpdb->insert query changes to SHOW COLUMNS query Output
- Fixing wpdb->get_results and wpdb->prepare?
- How does the WXR file differ from the WPDB?
- WordPress SQL query – returning ‘true’ ‘false’ or ‘null’
- Rolling Back from current WordPress version to previous one
- $wpdb query a post type within a specific taxonomy term while ordering posts by custom meta value?
- How to get an array of user roles with or without a specific capability?
- What is wrong with this wpdb update?
- using $wpdb to insert a form into a post
- wp_create_user not properly entering password
- Wp_query function to search from product_title ‘OR’ product tags name
- Constructing a dynamic WPDB query with multiple LIKEs
- Foreach loop not working as expected – custom tables and references while submitting a form
- Query insert query executing multiple times
- Undefined offset: 0
- Connect to separate database using $wpdb and authenticate user
- How to access PostgreSQL using WPDB?
- how to use $wpdb->prepare to update a custom table
- 301 Redirect Code
- Counting posts with argument without retrieving the posts
- how to assign content to a different author while loading content
- Create new database through static page code
- Register custom table for WP to use in a plugin
- wpdb->get_row is selecting the variable as a column name
- WordPress “wpdb->update” – Append Text Value
- Display category names on edit user profile using $wpdb
- Need help converting get_user_meta [keys] into own array
- Can’t call WPDB inside RSS template
- wpdb and acf via wp rest api
- WPDB SQL Ignore `post_status` Parameter
- wpquery properties last_query and last_result : should these be public or private?
- Query and get meta as object(stdClass) on wp postmeta table?
- How do I query a table?
- check that the data exists before sending it to wpdb
- wpdb->insert with special chars failing with collation utf8mb4_unicode_520_ci
- no result returns when using $wpdb->get_results with where clause
- SQL queries to another wordpress site
- PHP | left join avg query give me Array()
- update not working using wpdb
- get_posts() SQL Injection
- og:image functions.php
- wpdb replace returning 1 where delete and insert is expected
- update_post_meta not working in template_redirect action
- How to work with constraints on wordpress user metadata?
- $wpdb select returns empty array
- Show error messages to a user when database insert fails
- Debugging db calls: $wpdb->insert works on test site, not on identical production site
- Intermittent problem writing update_user_meta
- How to use WHERE NOT EXISTS query to avoid duplicate entry using $wpdb to save in custom table?
- Combine posts and postmeta
- Get 3 row ID’s via ARRAY_A
- Getting record from three wpdb tables
- wpdb get_row database query inquiry
- Depreciated Call -> Function wpdb::escape()
- How do I update post based on meta_key in another table?
- Inserting and updating rows with wpdb indreases integer fields by 1 point sometimes
- Retrieve a list of users based on some conditions
- wp_commentdata: error in documentation?
- Echo only gives me the first part of string
- wp-postratings: list current user’s unrated posts
- esc_sql inserting weird chars to DB
- Error inserting row into table
- Retriving array size from serialized data
- How to update user profile or inputing any data to the wp db from external site?
- Custom query (author is post_author or meta co_author) with Pagenavi pagination
- Get comments after specific date
- get only 1 wpdb and get taxonomy, post to next page [closed]
- WP Recommended Table Exclusions?