0

I am looking to query and pull a list of all custom posts 'foo' that have no featured image set and/or have no text copy (from the WP editor). The list will be used to determine which posts need content and/or a featured image. (We're importing a huge database from an outside source).

I'm starting with this-

$result = new WP_Query( array( 'posts_per_page' => -1, 'meta_key' => '_thumbnail_id', 'post_type' => 'foo' ) );

How would I change this to 1) exclude any post with a featured images set [I realize as it is now it includes them] and 2) also exclude any post that has content in the post editor?

1

Featured image part is easy enough, you know what custom field is called, you just need to tweak it a bit for NOT EXISTS condition for it, see Custom Field Parameters in Codex.

Empty content is harder, that is not something WP_Query does. However in SQL it should be easy (content field equals empty string or along those lines) so you could run custom query via wpdb for that condition or add it via filter to WP_Query (which is probably overkill unless you really need these combined together, doesn't seem it's that important from description).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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