0

I'm trying to come up with a simple query to return an array of unique author IDs that have a post_status of 'publish' and a post_type of 'job'.

I know I can query using:

$args = array(
'post_type' => 'job',
'post_status' => 'publish'
);
$published_jobs = new WP_Query( $args );

But this seems horribly inefficient to iterate through the results when all I want is an array of unique author IDs. At most we will have 30 or so authors, but could have thousands of job posts.

Any suggestions? Thanks!

1 Answer 1

0

The most efficient means would be to query directly via wpdb:

$author_ids = $wpdb->get_col(
    "
    SELECT DISTINCT post_author
    FROM $wpdb->posts
    WHERE post_type = 'job'
    AND post_status = 'publish'
    "
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.