Heyho,
I've got a problem getting the post_status of a WP_PostObject which is a Woocommerce-Product. I get all products doing this query:
$onlineShopProducts = get_posts([
'post_type' => ['product', 'product_variation'],
'orderby' => 'post_title',
'order' => 'ASC',
'numberposts' => -1
]);
Now I want to filter out all products which are in status draft during a foreach-loop:
foreach ($onlineShopProducts as $onlineShopProduct){
if($onlineShopProduct->post_status != 'publish'){
continue;
}
doSomething($onlineShopProduct)
}
but $onlineShopProduct->post_status and get_post_status($onlineShopProduct->ID) both return "publish", even tho they are set "Draft" in the product-edit-view... (it's in german)
is there some sort of post_meta I have to query or is this a know bug of some sort? How can I filter out the drafted products?
Greetings
get_posts
by default will ignore caching and give a performance hit unlesssuppress_filters
is set to false.WP_Query
does not have this limitationget_posts
to tell it which post statuses you want, you don't need to callget_post_status
. If you don't wantdraft
posts, just say so toget_posts
, the if check you're having problems with is unnecessary. Also keep in mind that WooCommerce and other 3rd party plugins are off topic, and be nice, your last comment was quite rude. Aside from a code of conduct, I'm not a support desk employee, my time is volunteered and unpaid, and there are no entitlements.