dimanche 1 mars 2015

Hide private posts on woocommerce category page

I am trying to modify the product loop from my functions.php file to exclude private posts from product category pages when admin users are logged in. I have found a number of approaches through a bit of searching but am struggling to modify the below code to achieve what I am after. -



add_filter('posts_where', 'no_privates');
function no_privates($where) {
if( is_admin() ) return $where;

global $wpdb;
return " $where AND {$wpdb->posts}.post_status != 'private' ";
}


This works great but I am struggling to modify it to allow Admins to preview the posts or view the individual products pages for editing and publishing. I was hoping someone could help me modify the code to get it working. Sorry if this is a simple solution, still at the early stages of learning php :-)


Cheers


Rich


Aucun commentaire:

Enregistrer un commentaire